Advertisement
MrKubic

Untitled

Feb 12th, 2017
3,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>
  2. SoftwareSerial mySerial(2, 3); // RX, TX
  3.  
  4. int val;
  5. int LED1 = 9;
  6. int LED2 = 10;
  7. int LED3 = 11;
  8. int LED4 = 12;
  9. void setup()
  10. {
  11.   mySerial.begin(38400);
  12.   pinMode(LED1, OUTPUT);
  13.   pinMode(LED2, OUTPUT);
  14.   pinMode(LED3, OUTPUT);
  15.   pinMode(LED4, OUTPUT);
  16.   digitalWrite(LED1, LOW);
  17.   digitalWrite(LED2, LOW);
  18.   digitalWrite(LED3, LOW);
  19.   digitalWrite(LED4, LOW);
  20. }
  21. void loop()
  22. {
  23.   if (mySerial.available())
  24.   {
  25.     val = mySerial.read();
  26.     if (val == '1'){digitalWrite(LED1, HIGH);}
  27.     if (val == '2'){digitalWrite(LED1, LOW);}
  28.    
  29.     if (val == '3'){digitalWrite(LED2, HIGH);}
  30.     if (val == '4'){digitalWrite(LED2, LOW);}
  31.    
  32.     if (val == '5'){digitalWrite(LED3, HIGH);}
  33.     if (val == '6'){digitalWrite(LED3, LOW);}
  34.    
  35.     if (val == '7'){digitalWrite(LED4, HIGH);}
  36.     if (val == '8'){digitalWrite(LED4, LOW);}
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement