Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String voice;
- #define redLed 2 //Connect red Led to pin 2
- #define blueLed 3 //Connect blue Led to pin 3
- void setup()
- {
- Serial.begin(9600); //Set rate for communicating with phone (baud rate)
- pinMode(redLed, OUTPUT); //Set redLed as an output
- pinMode(blueLed, OUTPUT); //Set blueLed as an output
- digitalWrite(redLed, LOW); // initially keeping the led's off
- digitalWrite(blueLed, LOW);
- }
- void loop()
- {
- while(Serial.available()) //Check if there are available bytes to read
- {
- delay(10); //Delay to make it stable
- char c = Serial.read(); //Conduct a serial read
- if (c == '#'){
- break; //Stop the loop once # is detected after a word
- }
- voice += c; //here the total voice is being collected word by word
- }
- if (voice.length() >0)
- {
- Serial.println(voice);
- if(voice == "*switch both on"){
- switchon();
- }
- else if(voice == "*switch both off"){
- switchoff();
- }
- else if(voice == "*red light on"){
- digitalWrite(redLed, HIGH);
- }
- else if(voice == "*red light off"){
- digitalWrite(redLed, LOW);
- }
- else if(voice == "*blue light on"){
- digitalWrite(blueLed, HIGH);
- }
- else if(voice == "*blue light off"){
- digitalWrite(blueLed, LOW);
- }
- voice="";
- }
- }
- void switchon()
- {
- digitalWrite(redLed, HIGH);
- digitalWrite(blueLed, HIGH);
- }
- void switchoff()
- {
- digitalWrite(redLed, LOW);
- digitalWrite(blueLed, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement