/*************************** * This code is designed for pfodApp controlling Arduino Uno * See www.pfod.com.au for pfodApp and pfodParser library ****************************/ #include #include // include the library pfodParser parser; // create the cmd parser // Pin 3 if the output being switched. // give it a name: int switchedOutput = 3; // the setup routine runs once when you press reset: void setup() { Serial.begin(9600); for (int i=3; i>0; i--) { // wait a few secs to see if we are being programmed delay(1000); } // initialize the digital pin as an output. pinMode(switchedOutput, OUTPUT); digitalWrite(switchedOutput, LOW); // start with output low (off) } // the loop routine runs over and over again forever: void loop() { byte in = 0; byte cmd = 0; if (Serial.available()) { in = Serial.read(); // read the next char cmd = parser.parse(in); // pass it to the parser returns non-zero when a command is fully parsed if (cmd != 0) { // have parsed a complete msg { to } if ('.' == cmd) { // pfodApp has connected and sent {.} it is asking for the main menu // toggle the output and send back Close Connection message with current state of output // either {!Output OFF} or {!Output ON} Serial.print(F("{!")); // send start of close connection message boolean outputState = digitalRead(switchedOutput); if (outputState == LOW) { digitalWrite(switchedOutput, HIGH); // was off turn on Serial.print(F("Output is ON")); // change this to your own message } else { digitalWrite(switchedOutput, LOW); // was on turn off Serial.print(F("Output is OFF")); // change this to your own message } Serial.print(F("}")); // send closing } to complete pfod message, pfodApp will exit and display your message // you can add any code here that is needed to close the connection on the micro side. // nothing for the ITead Studio BT Shield } } cmd = 0; // have processed this cmd now // so clear it and wait for next one } // else no serial chars just loop }