]> git.piffa.net Git - sketchbook_andrea/blobdiff - programming/loops/loop_2_array_loop_serial/loop_2_array_loop_serial.ino
Loop e data type strutturati
[sketchbook_andrea] / programming / loops / loop_2_array_loop_serial / loop_2_array_loop_serial.ino
index 7591641437c6e15e4d9a698bc474a85e8e4f8137..287628af8940dd7d61529bea3fea13b9fc1519d6 100644 (file)
@@ -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);