Advertisement
stirante

Untitled

Dec 19th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. int pin = LED_BUILTIN;
  2. bool isOn = false;
  3. void setup() {
  4.   Serial.begin(9600);
  5.   pinMode(pin, OUTPUT);
  6. }
  7.  
  8. void sendUpdate() {
  9.       if (isOn) {
  10.         Serial.write(0x00);
  11.         Serial.write(0xFF);
  12.       }
  13.       else {
  14.         Serial.write(0x00);
  15.         Serial.write(0x00);
  16.       }
  17. }
  18.  
  19. void loop() {
  20.   if (Serial.available() >= 2) {
  21.     int a = Serial.read();
  22.     int b = Serial.read();
  23.     if (a == 0xFF && b == 0xFF) {
  24.       digitalWrite(pin, HIGH);
  25.       isOn = true;
  26.       sendUpdate();
  27.     }
  28.     else if (a == 0xFF && b == 0x00) {
  29.       digitalWrite(pin, LOW);
  30.       isOn = false;
  31.       sendUpdate();
  32.     }
  33.     else if (a == 0xFF && b == 0x01) {
  34.       sendUpdate();
  35.     }
  36.   }
  37.   delay(10);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement