/* Title: attiny_i2c_slave1.ino Author: Lucas Lim Date Created: 29/04/2019 Last Modified: 29/04/2019 Purpose: Receive data from MASTER via the I2C bus Blink the LED */ #include #define I2C_SLAVE_ADDRESS (1) const int ledPin = 4; //PB4 - Arduino Pin No. 4 //int times = 0; //Number of times that LED will blink byte received = 0; //Received data(on number of times that LED will blink) from MASTER void setup() { TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network as slave } void blink_led(int times) { while(times--) { digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(500); } } void loop() { if (TinyWireS.available()) { received = TinyWireS.receive(); blink_led(received); } received = 0; // This needs to be here TinyWireS_stop_check(); }