/* Bluetooth Retracting Projector Screen - Bluetooth Test This sketch tests the serial connection between a Android app and a Bluetooth chip attached to the Arduino. Commands are sent from th app via Bluetooth to the Arduino to turn the on board LED on/off. Created 22 Feb 2012 modified xx Xxx 20xx by Brett Russell */ // Define Constants and Variables const int ledPin = 13; // names the on board LED pin int count; //counting variable for flashing LED int state; void setup() { // initialize LED Pin as output pinMode(ledPin, OUTPUT); // initialize serial communications: Serial.begin(9600); // set LED initial state as off digitalWrite(ledPin, LOW); // write in LED state state = digitalRead(ledPin); } void loop() { // check if serial data is available if ( Serial.available() > 0 ) { // write the serial command value byte command = Serial.read(); // 1 = Blink Fast, 2 = Blink Slow, 3 = Led off //read the LED state state = digitalRead(ledPin); // if the command sent is 1 and LED is off, blink LED fast if (command == 1 && state == LOW) { count = 0; //reset count while (count < 20 && command != 3) { // flashes LED digitalWrite (ledPin, HIGH); delay(250); digitalWrite (ledPin, LOW); delay(250); //incrament count count = ++count; //check command command = Serial.read(); } } // if the command sent is 2 and the LED is off else if (command == 2 && state == LOW) { count = 0; //reset count while (count < 10 && command != 3) { // flashes LED digitalWrite (ledPin, HIGH); delay(500); digitalWrite (ledPin, LOW); delay(500); //incrament count count = ++count; //check command command = Serial.read(); } } } }