document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. String voice;
  2. #define redLed 2    //Connect red Led to pin 2
  3. #define blueLed 3    //Connect blue Led to pin 3
  4. void setup()
  5. {
  6.   Serial.begin(9600);            //Set rate for communicating with phone (baud rate)
  7.   pinMode(redLed, OUTPUT);       //Set redLed as an output
  8.   pinMode(blueLed, OUTPUT);       //Set blueLed as an output
  9.   digitalWrite(redLed, LOW);     // initially keeping the led\'s off
  10.   digitalWrite(blueLed, LOW);    
  11. }
  12. void loop()
  13. {
  14.   while(Serial.available())    //Check if there are available bytes to read
  15.   {
  16.     delay(10);                 //Delay to make it stable
  17.     char c = Serial.read();    //Conduct a serial read
  18.     if (c == \'#\'){
  19.       break;                   //Stop the loop once # is detected after a word
  20.     }
  21.     voice += c;                //here the total voice is being collected word by word
  22.   }
  23.     if (voice.length() >0)
  24.     {
  25.       Serial.println(voice);
  26.       if(voice == "*switch both on"){
  27.         switchon();
  28.       }              
  29.       else if(voice == "*switch both off"){
  30.         switchoff();
  31.       }              
  32.       else if(voice == "*red light on"){  
  33.        
  34.         digitalWrite(redLed, HIGH);
  35.       }
  36.       else if(voice == "*red light off"){
  37.         digitalWrite(redLed, LOW);
  38.       }
  39.       else if(voice == "*blue light on"){
  40.         digitalWrite(blueLed, HIGH);
  41.       }
  42.       else if(voice == "*blue light off"){
  43.         digitalWrite(blueLed, LOW);
  44.       }
  45.       voice="";
  46.     }
  47. }
  48. void switchon()              
  49. {
  50.   digitalWrite(redLed, HIGH);
  51.   digitalWrite(blueLed, HIGH);
  52. }
  53. void switchoff()          
  54. {
  55.   digitalWrite(redLed, LOW);
  56.   digitalWrite(blueLed, LOW);
  57. }
');