/* Michael Kontopoulos 2009 Sigh Collector - Sender Code */ #include NewSoftSerial mySerial = NewSoftSerial(4, 5); //instead of 1,2 (rx,tx) //PINS int stretcher = 1; int threshPin = 0; int threshLed=3; int val = 0; // variable to store the value coming from the sensor int pot = 0; int sighPin = 13; //VARIABLES int const numVals = 40; int breathVals[numVals]; //int diffVals[numVals/4]; int total=0, diffTotal=0, avg=0, rate=0; int state = 0; int threshold=0; int normBreath; int prevMillis=0; boolean possibleSigh; void setup() { Serial.begin(9600); mySerial.begin(9600); pinMode(sighPin, OUTPUT); pinMode(stretcher, INPUT); possibleSigh = false; } void loop() { serialHandler(); val = analogRead(stretcher); threshold = analogRead(threshPin); // Serial.println(val); checkSigh(avg); //Array of the last 30 breath values for(int i=1; i= threshold) && (avg < 400)) { // digitalWrite(threshLed, HIGH); possibleSigh = true; } else { //digitalWrite(threshLed, LOW); } } long int prevMillz = 0; void checkSigh(int average) { if(possibleSigh) { prevMillis = millis(); //when avg drops back down, register the sigh if(average <= 15) { mySerial.println(8, DEC); Serial.println("sigh detected. mobile unit"); digitalWrite(sighPin, HIGH); delay(1000); digitalWrite(sighPin, LOW); possibleSigh=false; } } else possibleSigh=false; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void serialHandler() { if (mySerial.available()) { Serial.print((char)mySerial.read()); } if (Serial.available()) { mySerial.print((char)Serial.read()); } delay(100); }