#include int state = HIGH; // the current state of the output pin int reading; // the current reading from the input pin int previous = LOW; // the previous reading from the input pin long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time, increase if the output flickers int randomnumber = 0; void setup() { Wire.begin(); // join i2c bus (address optional for master) pinMode(13, OUTPUT); } void loop() { randomnumber = randomnumber++; if (randomnumber==51) { randomnumber=0; } reading = digitalRead(53); if (reading==1 && previous==0 && millis() - time > debounce) { sendcom(11, randomnumber); time = millis(); } previous = reading; reading = digitalRead(51); if (reading==1 && previous==0 && millis() - time > debounce) { sendfx(3, randomnumber); time = millis(); } previous = reading; reading = digitalRead(49); if (reading==1 && previous==0 && millis() - time > debounce) { sendmusic(0, 2); time = millis(); } previous = reading; } void sendfx (byte x, byte y) { Wire.beginTransmission(3); // transmit to device #3 Wire.send(1); // Sends On Wire.send(x); // sends directory Wire.send(y); // sends file number Wire.endTransmission(); // stop transmitting } void sendcom (byte x, byte y) { Wire.beginTransmission(2); // transmit to device #2 Wire.send(1); // Sends On Wire.send(x); // sends directory Wire.send(y); // sends file number Wire.endTransmission(); // stop transmitting } void sendmusic (byte x, byte y) { Wire.beginTransmission(1); // transmit to device #1 Wire.send(1); // Sends On Wire.send(x); // sends directory Wire.send(y); // sends file number Wire.endTransmission(); // stop transmitting }