Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #define LED_PIN 13
- #define LED_1 12
- #define LED_2 11
- int x;
- void setup() {
- Wire.begin(9); // Start I2C Bus as a Slave (Device Number 9)
- Wire.onReceive(receiveEvent); // register event
- pinMode(LED_PIN, OUTPUT);
- pinMode(LED_1, OUTPUT);
- pinMode(LED_2, OUTPUT);
- digitalWrite(LED_PIN, LOW);
- digitalWrite(LED_1, LOW);
- digitalWrite(LED_2, LOW);
- x = 0;
- }
- void loop() {
- //If value received is 0 blink LED 1
- if (x == 0) {
- digitalWrite(LED_1, HIGH);
- delay(200);
- digitalWrite(LED_1, LOW);
- delay(200);
- }
- //If value received is 1 blink LED 2
- if (x == 1) {
- digitalWrite(LED_2, HIGH);
- delay(200);
- digitalWrite(LED_2, LOW);
- delay(200);
- }
- }
- void receiveEvent(int howMany) {
- x = Wire.receive(); // receive byte as an integer
- }
Advertisement
Add Comment
Please, Sign In to add comment