/* Michael Kontopoulos 2009 Pacing Track (Sender) */ #include NewSoftSerial mySerial = NewSoftSerial(4, 5); int val1, val2; int const numVals = 20; int proxVals1[numVals]; int proxVals2[numVals]; int total1=0, total2=0; int avg1=0, avg2=0; int reading1, reading2; // the current reading from the input pins int previous1, previous2 = LOW; // the previous reading from the input pins long time1 = 0; // the last time the output pin was toggled long time2 = 0; long debounce = 2000; // the debounce time, increase if the output flickers int highVal = 440; int lowVal = 160; void setup() { val1=0; val2=0; Serial.begin(9600); mySerial.begin(9600); } void loop() { serialHandler(); val2 = analogRead(2); val1 = analogRead(1); //Array of the last 30 breath values for(int i=1; i highVal)) reading1 = HIGH; else reading1 = LOW; if((avg2 highVal)) reading2 = HIGH; else reading2 = LOW; //Register button pressing //Includes Debouncing if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce) { mySerial.println(8, DEC); Serial.println("red"); time1 = millis(); } previous1 = reading1; if (reading2 == HIGH && previous2 == LOW && millis() - time2 > debounce) { mySerial.println(9, DEC); Serial.println("black"); time2 = millis(); } previous2 = reading2; } // end main void serialHandler() { if (mySerial.available()) { Serial.print((char)mySerial.read()); } if (Serial.available()) { mySerial.print((char)Serial.read()); } delay(100); }