/* Bluetooth Retracting Projector Screen Pot Sensor Test This sketch uses a potentiometer to turn a LED on and off. The LED is off in the upper and lower 5% of the range of the pot. It prints the current pot value to serial for calibration. Created 20 Feb 2012 modified xx Xxx 20xx by Brett Russell */ // Define Constants const int analogPin = A0; // pin that the pot is attached to const int thresholdUp = 972; // the analog input threshold level that determines when the screen is up const int thresholdDown = 51; // the analog input threshold level that determines when the screen is down const int ledPin = 13; // sets LED pin void setup() { // initialize serial communications Serial.begin(9600); // sets LED pin as output pinMode(ledPin,OUTPUT); digitalWrite(ledPin, LOW); } void loop() { // read the value of the potentiometer int potPosition = analogRead(analogPin); // check if pot is in on range if (potPosition > thresholdDown && potPosition < thresholdUp) { do { // turn LED on digitalWrite(ledPin, HIGH); // read pot position potPosition = analogRead(analogPin); //print pot position to serial Serial.println(potPosition); } // recheck pot position while(potPosition > thresholdDown && potPosition < thresholdUp); } //Shuts off LED if pot leaves on range digitalWrite( ledPin, LOW); }