Guest User

Untitled

a guest
Jul 3rd, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1.  
  2. // Code for master final project's board
  3.  
  4.  
  5. #include <TinyWireM.h>
  6.  
  7.  
  8. int LED=0;
  9.  
  10. void setup() {
  11.  
  12. TinyWireM.begin(); //initialization of communication
  13. pinMode(LED,OUTPUT);
  14. delay(200);
  15. }
  16.  
  17.  
  18. void loop() {
  19.   TinyWireM.requestFrom(8,1);     //asks the slave #8 to send a byte
  20.  while(TinyWireM.available()){       //puts what it's got into 'got' variable
  21.   int got=TinyWireM.receive();
  22.  
  23. if (got == 1){                  //if the slave sent '1', the master turns led on for 3 seconds
  24.     digitalWrite(LED, HIGH);
  25.     delay(700);
  26.     digitalWrite(LED, LOW);
  27.     delay(100);
  28.    
  29.     }
  30. if (got == 0){             //if the slave sent '0', the master blinks LED twice
  31.     digitalWrite(LED, HIGH);
  32.     delay(100);
  33.     digitalWrite(LED, LOW);
  34.     delay(100);
  35.     digitalWrite(LED, HIGH);
  36.     delay(100);
  37.     digitalWrite(LED, LOW);
  38.     delay(100);
  39.     }
  40.  }
  41.  delay(100);
  42.  }
Advertisement
Add Comment
Please, Sign In to add comment