Sto analizzando uno sketch per poterlo ampliare su più led. Lo sketch è il seguente:
// Data received from the serial port
int val;
//LEDs are connected to the following pins
int pins[] = {4,5,6,7,8};
void setup() {
for(int i=0; i<5; i++){
pinMode(pins*, OUTPUT); // Set pins as OUTPUTs*
- }*
- Serial.begin(9600); // Start serial communication at 9600 bps*
}
void loop() {
if (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
// Turn on LEDs, depending on pitches received
- if (val == 60) { digitalWrite(pins[0],HIGH); } else*
- if (val == 62) { digitalWrite(pins[1],HIGH); } else*
- if (val == 64) { digitalWrite(pins[2],HIGH); } else*
- if (val == 65) { digitalWrite(pins[3],HIGH); } else*
- if (val == 67) { digitalWrite(pins[4],HIGH); } else*
- if (val==0) { resetLEDs(); }*
}
}
//Function that turns all the LEDs off
void resetLEDs(){ - for(int i=0; i<5; i++){*
_ digitalWrite(pins*,LOW);_
_ }_
_}*_
Ora mi è chiaro che i pins connessi sono il 4,5,6,7,8 ma non mi sono chiari i valori tra le parentesi quadre nelle istruzioni digitalwrite che sono 0,1,2,3,4 mandati in stato HIGH quando i valori ricevuti sono 60,62,64,65,67. Perchè 0,1,2,3,4 e non 4,5,6,7,8 ?
Scusate la domanda per molti banale ma sono alle prime armi.
Grazie in anticipo.