Lab_interaccio/2012/Oscar_sanoguera/Oscar_sanoguera.ino
2025-02-25 21:29:42 +01:00

42 lines
1 KiB
C++

/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
const uint8_t pin_in[10] = {3,4,5,6,7,8,9,10,11,12}; //Pines de entrada
uint8_t pin_in_ant[10] = {0,0,0,0,0,0,0,0,0,0}; //Valores iniciales de flag de pin
const uint8_t note[10] = {0x30,0x35,0x40,0x45,0x50,0x55,0x70,0x75,0x80,0x90}; //Nota variable desde 0x30 a 0x90
const uint8_t chanel= 0x90; //Canal variable desde 0x90 a 0x9F
boolean sensorValue=0;
void setup() {
Serial.begin(31250);
for (int i=0; i<10; i++) {pinMode(pin_in[i], INPUT); digitalWrite(pin_in[i], HIGH);}
}
void loop() {
for (int i=0; i<10; i++) {
sensorValue = digitalRead(pin_in[i]);
if (pin_in_ant[i]!= sensorValue)
{
pin_in_ant[i] = sensorValue;
if (!sensorValue) noteOn(chanel, note[i], 0x45); //Nota ON
else noteOn(chanel, note[i], 0x00); //Nota OFF
}
delay(10);
}
}
void noteOn(byte cmd, byte data1, byte data2) {
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
}