Lab_interaccio/2012/diego paonessa/sketch_sweetloop_master/sketch_sweetloop_master.ino

105 lines
3.7 KiB
Arduino
Raw Normal View History

2025-02-25 21:29:42 +01:00
#include <Wire.h>
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 ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8;
int limite = 500;
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(); // join i2c bus (address optional for master)
}
void loop() {
// unit, bpm, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
if ((analogRead(A0)>limite)||(analogRead(A1)>limite))
{
patron(1, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(0, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(1, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(0, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(1, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(0, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(1, 100, 0, 0,255, 0, 0,255, 0, 0,255, 0, 0,255, 0, 0,255, 0);
patron(0, 100, 0, 0,255, 0, 0,255, 0, 0,255, 0, 0,255, 0, 0,255, 0);
patron(1, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
patron(0, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
patron(1, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
patron(0, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
patron(1, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(0, 100,128, 64,255, 16, 8, 4, 2, 1,255, 1, 2, 4, 8,255, 32, 64);
patron(1, 100,128,128,128,128, 0, 0,128, 0,255, 0, 0,128, 0,255, 0,255);
patron(0, 100,128,128,128,128, 0, 0,128, 0,255, 0, 0,128, 0,255, 0,255);
patron(1, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
patron(0, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
//patron(0, 100,255, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0);
}
}
void patron(int unit, 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 )
{
if(unit == 0)
{
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);
}
else
{
//Aqui se manda por la libreria WIRE
Wire.beginTransmission(unit); // transmit to device "unit"
Wire.write(bpm);
Wire.write(step1);
Wire.write(step2);
Wire.write(step3);
Wire.write(step4);
Wire.write(step5);
Wire.write(step6);
Wire.write(step7);
Wire.write(step8);
Wire.write(step9);
Wire.write(step10);
Wire.write(step11);
Wire.write(step12);
Wire.write(step13);
Wire.write(step14);
Wire.write(step15);
Wire.write(step16);
Wire.endTransmission(); // stop transmitting
}
}