Advertisement
MateuszJasek

Arduino WiFiBee

Nov 20th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. char commandC;
  2. String command;
  3.  
  4.  
  5. void setup() {
  6.   Serial.begin(115200);
  7.   Serial1.begin(115200);
  8.  
  9.   // Wait for PuTTY
  10.   while(!Serial1);
  11.   delay(1000);
  12.   Serial1.println("");
  13.   Serial1.println("\t\tSuccessfully connected with arduino!");
  14.   Serial1.println("");
  15.   Serial1.println("");
  16. }
  17. void loop() {
  18.  
  19.   while(Serial.available()) {
  20.     delay(5);
  21.     Serial1.write(Serial.read());
  22.   }
  23.    
  24.   while(Serial1.available()) {
  25.     commandC = Serial1.read();
  26.     command = String(command + commandC);
  27.  
  28.     Serial.print("Current char: ");
  29.     Serial.println(commandC);
  30.     Serial.println();
  31.     Serial.print("Command: ");
  32.     Serial.println(command);
  33.    
  34.     if(command == "rLed") {
  35.         digitalWrite(9, HIGH);
  36.         delay(1500);
  37.         digitalWrite(9, LOW);
  38.  
  39.         commandC = '\0';
  40.         command = "\0";
  41.      
  42.       } else if(command == "gLed") {
  43.         digitalWrite(8, HIGH);
  44.         delay(1500);
  45.         digitalWrite(8, LOW);
  46.      
  47.       } else if(command == "bLed") {
  48.         digitalWrite(7, HIGH);
  49.         delay(1500);
  50.         digitalWrite(7, LOW);
  51.        
  52.       }
  53.   }
  54.  
  55.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement