Created
March 14, 2015 04:57
-
-
Save mschlenker/3e98a33ef08596b80515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I used the Serial Call and Response example sketch and modified it | |
This program similarly sends an ASCII A (byte of value 65) on | |
startup and repeats that until it gets some data in. | |
Then it waits for a byte in the serial port, and | |
sends sensor values whenever it gets a byte in. | |
The circuit: | |
* 5 piezos hooked up to Analog Pins 0-4 | |
[Use roughly 1M resistors for each] | |
*/ | |
const int firstSensor = 0; | |
//declares that each sensor is connected to Analog Pins 0-4 | |
const int secondSensor = 1; | |
const int thirdSensor = 2; | |
const int fourthSensor = 3; | |
const int fifthSensor = 4; | |
int sensorReading1 = 0; // first analog sensor reading | |
int sensorReading2 = 0; // second analog sensor reading | |
int sensorReading3 = 0; // and so on... | |
int sensorReading4 = 0; | |
int sensorReading5 = 0; | |
int inByte = 0; // incoming serial byte | |
const int threshold = 100; | |
//constant threshold of the knock sensors | |
void setup() | |
{ | |
// start serial port at 9600 bps: | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
// get incoming byte: | |
inByte = Serial.read(); | |
sensorReading1 = analogRead(firstSensor); //read sensor | |
if (sensorReading1 >= threshold) { | |
//if reading is greater than threshold | |
Serial.println("k"); //print designated letter” | |
} | |
sensorReading2 = analogRead(secondSensor); | |
if (sensorReading2 >= threshold) { | |
Serial.println("b"); | |
} | |
sensorReading3 = analogRead(thirdSensor); | |
if (sensorReading3 >= threshold) { | |
Serial.println("s"); | |
} | |
sensorReading4 = analogRead(fourthSensor); | |
if (sensorReading4 >= threshold) { | |
Serial.println("c"); | |
} | |
sensorReading5 = analogRead(fifthSensor); | |
if (sensorReading5 >= threshold) { | |
Serial.println("h"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix for https://plus.google.com/105372758468862415237/posts/6dUk78F6LUB