Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
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");
}
}
@mschlenker

This comment has been minimized.

Copy link
Owner Author

mschlenker commented Mar 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.