X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=programming%2Floops%2Floop_2_array_loop_serial%2Floop_2_array_loop_serial.ino;h=287628af8940dd7d61529bea3fea13b9fc1519d6;hp=7591641437c6e15e4d9a698bc474a85e8e4f8137;hb=389f454b12f2c526fbc707d6b4903e7dfb8f5620;hpb=487c31ee83fb81e856593ae272d2d76a2a5c1a78 diff --git a/programming/loops/loop_2_array_loop_serial/loop_2_array_loop_serial.ino b/programming/loops/loop_2_array_loop_serial/loop_2_array_loop_serial.ino index 7591641..287628a 100644 --- a/programming/loops/loop_2_array_loop_serial/loop_2_array_loop_serial.ino +++ b/programming/loops/loop_2_array_loop_serial/loop_2_array_loop_serial.ino @@ -1,22 +1,22 @@ /* For Loop Iteration - + Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then in reverse. - + The circuit: * LEDs from pins 2 through 9 to ground - + Schemi: - http://lab.piffa.net/schemi/8_led_single_res_bb.png - http://lab.piffa.net/schemi/8_led_single_res_schem.png - + http://www.arduino.cc/en/Tutorial/ForLoop */ byte ledPins[8] = { // Domanda: cosa succede se uso int? - 2,3,4,5,6,7,8,9} -; //Array + 2, 3, 4, 5, 6, 7, 8, 9 + } ; //Array int timer = 100; // Pausa per far brillare i LED void setup() { @@ -25,7 +25,7 @@ void setup() { for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) { pinMode(ledPins[thisPin], OUTPUT); Serial.print("Inizializzato pin n. "); - Serial.println( thisPin); + Serial.println(thisPin); } Serial.print("Dimesione array: "); @@ -38,16 +38,16 @@ void loop() { Serial.print("Accensione pin n. "); Serial.println(thisPin); // turn the pin on: - digitalWrite(ledPins[thisPin], HIGH); - delay(timer); + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); // turn the pin off: - digitalWrite(ledPins[thisPin], LOW); + digitalWrite(ledPins[thisPin], LOW); // Debug } // loop from the highest pin to the lowest: - for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) { + for (int thisPin = sizeof(ledPins) - 1 ; thisPin > 0; thisPin--) { Serial.print("Accensione pin n. "); // Gli array sono indicizzati da 0 Serial.println(thisPin); digitalWrite(ledPins[thisPin], HIGH);