document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <Wire.h> // required library
  2. int LED = 13; //initialize pin 13 (led)
  3. int x = 0; //initialize variable x
  4. void setup() {
  5. pinMode (LED, OUTPUT); // Define pin13 as Output
  6. Wire.begin(9); // Start the I2C Bus as Slave on address 9
  7. Wire.onReceive(receiveEvent); // Attach a function to trigger when something is received.
  8. }
  9. void receiveEvent(int bytes) {
  10. x = Wire.read(); // read one character from the I2C
  11. }
  12. void loop() {
  13. //If value received is 0 blink LED for 200 ms
  14. if (x == 0) {
  15. digitalWrite(LED, HIGH);
  16. delay(200);
  17. digitalWrite(LED, LOW);
  18. delay(200);
  19. }
  20. //If value received is 3 blink LED for 400 ms
  21. if (x == 3) {
  22. digitalWrite(LED, HIGH);
  23. delay(400);
  24. digitalWrite(LED, LOW);
  25. delay(400);
  26. }
  27. }
');