const int PIN_GREEN = 0; const int PIN_RED = 1; const int PIN_BLUE = 2; const int PIN_GREEN2 = 5; const int PIN_RED2 = 4; const int PIN_BLUE2 = 3; #include // Include the required Wire library for I2C
#include int x = 0; void setup() { pinMode(PIN_RED, OUTPUT); pinMode(PIN_GREEN, OUTPUT); pinMode(PIN_BLUE, OUTPUT); pinMode(PIN_RED2, OUTPUT); pinMode(PIN_GREEN2, OUTPUT); pinMode(PIN_BLUE2, OUTPUT); digitalWrite(PIN_BLUE2, 1); delay(3000); digitalWrite(PIN_BLUE2, 0); // Start the I2C Bus as Slave on address 9 Wire.begin(9); // Attach a function to trigger when something is received. Wire.onReceive(receiveEvent); } int receiveCounter = 0; void receiveEvent(int bytes) { x = Wire.read(); // read one character from the I2C } void loop() { pinsDown(); //decimal to 6 bits binary number int fiveBits = x % 32; int bitSix = x / 32; if (bitSix == 1) digitalWrite(PIN_GREEN, 1); int fourBits = fiveBits % 16; int bitFive = fiveBits / 16; if (bitFive == 1) digitalWrite(PIN_RED, 1); int threeBits = fourBits % 8; int bitFour = fourBits / 8; if (bitFour == 1) digitalWrite(PIN_BLUE, 1); int twoBits = threeBits % 4; int bitThree = threeBits / 4; if (bitThree == 1) digitalWrite(PIN_GREEN2, 1); int oneBits = twoBits % 2; int bitTwo = twoBits / 2; if (bitTwo == 1) digitalWrite(PIN_RED2, 1); if (oneBits == 1) digitalWrite(PIN_BLUE2, 1); } void pinsDown() { digitalWrite(PIN_RED, 0); digitalWrite(PIN_GREEN, 0); digitalWrite(PIN_BLUE, 0); digitalWrite(PIN_RED2, 0); digitalWrite(PIN_GREEN2, 0); digitalWrite(PIN_BLUE2, 0); }