Facebook
From Diminutive Owl, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 336
  1. #include <Wire.h>
  2. int LED = 13;
  3. void setup() {
  4.   // Define the LED pin as Output
  5.   pinMode (LED, OUTPUT);
  6.   // Start the I2C Bus as Slave on address 9
  7.   Wire.begin(9);
  8.   // Attach a function to trigger when something is received.
  9.   Wire.onReceive(receiveEvent);
  10. }
  11. void receiveEvent(int bytes) {
  12.    int x = Wire.read();    // read one character from the I2C
  13.  
  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. }
  28. void loop() {
  29.   delay(100);
  30. }