#include int bpm, tempo; int c1 = 5; int c2 = 6; int c3 = 7; int c4 = 8; int c5 = 9; int c6 = 10; int c7 = 11; int c8 = 12; int counter = 0; int buffer[30]; boolean flag_ok=false; int ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8; //CAMBIAR ESTE CANAL POR EL NUMERO DE CANAL CORRESPONDIENTE const int CHANNEL = 5;//0 esta prohibido void setup() { Serial.begin(9600); // use a for loop to initialize each pin as an output: for (int thisPin = 5; thisPin < 13; thisPin++) { pinMode(thisPin, OUTPUT); } Wire.begin(CHANNEL); Wire.onReceive(receiveEvent); // register event } void loop() { if (flag_ok) patron(buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15], buffer[16]); } void patron(int bpm, int step1, int step2, int step3, int step4, int step5, int step6, int step7, int step8, int step9, int step10, int step11, int step12, int step13, int step14, int step15, int step16 ) { int seq[16] = {step1, step2, step3, step4, step5, step6, step7, step8, step9, step10, step11, step12, step13, step14, step15, step16}; for(int i=0 ; i<16 ; i++) { ch1 = seq[i] & 0x01; ch2 = (seq[i]>>1) & 0x01; ch3 = (seq[i]>>2) & 0x01; ch4 = (seq[i]>>3) & 0x01; ch5 = (seq[i]>>4) & 0x01; ch6 = (seq[i]>>5) & 0x01; ch7 = (seq[i]>>6) & 0x01; ch8 = (seq[i]>>7) & 0x01; digitalWrite(c1,ch1); digitalWrite(c2,ch2); digitalWrite(c3,ch3); digitalWrite(c4,ch4); digitalWrite(c5,ch5); digitalWrite(c6,ch6); digitalWrite(c7,ch7); digitalWrite(c8,ch8); tempo = 60000/(4*bpm); delay(tempo); } for (int thisPin = 5; thisPin < 13; thisPin++) digitalWrite(thisPin,LOW); flag_ok=false; } void receiveEvent(int howMany) { counter=0; while(1 < Wire.available()) // loop through all but the last { int aux = Wire.read(); // receive byte as a character buffer[counter] = aux; counter++; } int aux = Wire.read(); // receive byte as a character buffer[counter] = aux; counter++; flag_ok=true; }