#include int fsrAnalogPin = 1; int fsrReading; int LDRReading; int LDR_Pin = A0; Servo myservo; Servo outservo; int pos = 0; float pos2 = 0; boolean run; boolean isCalibrated = false; int birdCount = 0; int squirrelCount = 0; int lightAVG=0; int touchAVG=0; int progress=0; int touchThres = 100; int lightThres = 50; void setup(void) { Serial.begin(9600); myservo.attach(9); outservo.attach(10); run = false; outservo.write(0); myservo.write(0); } void loop(void) { fsrReading = analogRead(fsrAnalogPin); LDRReading = analogRead(LDR_Pin); Serial.print("Pad reading = "); Serial.println(fsrReading); Serial.print("Light reading = "); Serial.println(LDRReading); Serial.print("Pad AVG = "); Serial.println(touchAVG); Serial.print("Light AVG = "); Serial.println(lightAVG); Serial.println(birdCount); Serial.println(squirrelCount); if(isCalibrated==false){ delay(10); Serial.print("Progress = "); Serial.println(progress); lightAVG=lightAVG+LDRReading; touchAVG=touchAVG+fsrReading; progress++; if(progress==10){ lightAVG=(lightAVG/progress); touchAVG=(touchAVG/progress); isCalibrated=true; } } else{ delay(10); if (abs(fsrReading - touchAVG)>touchThres) { run = true; squirrelCount++; } if (abs(LDRReading - lightAVG)>lightThres) { run = true; birdCount++; Serial.print("RUNTRU"); } if (run) { Serial.print("RUNFOR"); for(pos = 0; pos < 90; pos += 1) { myservo.write(pos); delay(15); } for(pos = 90; pos>=1; pos-=1) { myservo.write(pos); delay(15); } pos2+=10; outservo.write(pos2); delay(15); run = false; } } }