/* Bluetooth Remote Projector Screen This sketch controls a bluetooth enabled Arduino which runs a projector screen up and down. Created 27 Mar 2012 modified xx Xxx 20xx by Brett Russell */ // Motor shield library #include // Define Constants and Variables AF_DCMotor motor(2, MOTOR12_1KHZ); //create motor on number 2 port, 1KHz pwm const int potPin = 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 byte command; int screenPosition; void setup() { // initialize serial communications: Serial.begin(9600); // set motor speed, 250/255 motor.setSpeed (250); } void loop() { // Turn off motor after correct position is reached or full stop command is sent motor.run(RELEASE); // check if serial data is available if ( Serial.available() > 0 ) { // write the serial command value command = Serial.read(); // 1 = Down, 2 = Up, 3 = Full stop // Check screen position screenPosition = analogRead(potPin); // if the command sent is 1 and the screen is up, lower the screen if (command == 1 && screenPosition > thresholdDown) { do { // Run screen down motor.run(FORWARD); // Check screen position screenPosition = analogRead(potPin); // Check for new seriel commands command = Serial.read(); } // Keep the screen running while it is not down and there is no full stop while (screenPosition > thresholdDown && command != 3); } // if the command sent is 2 and the screen is down, raise the screen else if (command == 2 && screenPosition < thresholdUp) { do { // Run screen up motor.run(BACKWARD); // Check screen position screenPosition = analogRead(potPin); // Check for new seriel commands command = Serial.read(); } // Keep the screen running while it is not down and there is no full stop while (screenPosition < thresholdUp && command != 3); } } }