/////////////////////////////ATtiny412 //define pins ////// I2C #define SDA_pin A1 // pin 4 #define SCL_pin A2 // pin 5 ////// SERIAL #define Tx_pin B2 #define Rx_pin B3 ////// OUTPUTS #define LED_Rgb A6 // pin2 #define LED_rGb A7 // pin3 #define LED_rgB A3 // pin7 ////// Variables # define baud_Rate 9600 # define myAddress 1 // add address here // RGB ARRAYS int RGB_Array[] = {LED_Rgb, LED_rGb, LED_rgB}; int RGB_ArrayCount = sizeof(RGB_Array) / sizeof(RGB_Array[0]); // OTHER variables int myDelay = 100; ////////////////////////////// //// INCLUDES #include ////////////////////////////// void setup() { // put your setup code here, to run once: // OUPUTS pinMode(LED_Rgb, OUTPUT); pinMode(LED_rGb, OUTPUT); pinMode(LED_rgB, OUTPUT); // COMMS RGB_off();// INITIAL STATE Wire.begin(myAddress); // join i2c bus with address #4 Wire.onReceive(receiveEvent); // register event // Serial Serial.swap(1);// solves single RGB red led problem Serial.begin(baud_Rate); // start serial for output while (!Serial); } void loop() { // put your main code here, to run repeatedly: delay(myDelay); } /////////////////////////////////////// void receiveEvent(int howMany) { int x = Wire.read(); // receive byte as an integer switch (x) { case 0: // OFF RGB_off(); break; case 1: // ON RGB_on(); break; default: RGB_off(); break; } } //////////////////// void RGB_off() { for (int k = 0; k <= RGB_ArrayCount - 1; k++) { digitalWrite(RGB_Array[k], HIGH); } } /////////////// void RGB_on() { // seperately on/off for (int k = 0; k <= RGB_ArrayCount - 1; k++) { digitalWrite(RGB_Array[k], LOW); } } ///////////////////