From 81ae6f5410398f1f3a59b671aa400338a8748284 Mon Sep 17 00:00:00 2001 From: Andrea Manni Date: Thu, 31 Mar 2016 15:39:06 +0200 Subject: [PATCH] loops array --- .../loops/loop_0_rider/loop_0_rider.ino | 4 +- .../loop_1_array_loop/loop_1_array_loop.ino | 27 ++++++----- .../loop_2_array_loop_serial.ino.ino} | 0 .../loop_3_multi_led/loop_3_multi_led.ino | 45 ------------------- .../loop_3_multi_led_random.ino} | 0 .../match_4_for_loop.ino} | 3 ++ .../match_5_while_loop.ino} | 0 7 files changed, 22 insertions(+), 57 deletions(-) rename programming/loops/{loop_4_multi_led_array/loop_4_multi_led_array.ino => loop_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino} (100%) delete mode 100644 programming/loops/loop_3_multi_led/loop_3_multi_led.ino rename programming/loops/{loop_5_multi_led_random/loop_5_multi_led_random.ino => loop_3_multi_led_random/loop_3_multi_led_random.ino} (100%) rename programming/loops/{loop_match_2_for_loop/loop_match_2_for_loop.ino => match_4_for_loop/match_4_for_loop.ino} (97%) rename programming/loops/{loop_match_2_while_loop/loop_match_2_while_loop.ino => match_5_while_loop/match_5_while_loop.ino} (100%) diff --git a/programming/loops/loop_0_rider/loop_0_rider.ino b/programming/loops/loop_0_rider/loop_0_rider.ino index 854f225..1549668 100644 --- a/programming/loops/loop_0_rider/loop_0_rider.ino +++ b/programming/loops/loop_0_rider/loop_0_rider.ino @@ -20,8 +20,8 @@ int pin4 = 4; int pin5 = 5; int pin6 = 6; int pin7 = 7; -int pin7 = 8; -int pin7 = 9; +int pin8 = 8; +int pin9 = 9; int timer = 100; void setup(){ diff --git a/programming/loops/loop_1_array_loop/loop_1_array_loop.ino b/programming/loops/loop_1_array_loop/loop_1_array_loop.ino index 42871ef..bb9662e 100644 --- a/programming/loops/loop_1_array_loop/loop_1_array_loop.ino +++ b/programming/loops/loop_1_array_loop/loop_1_array_loop.ino @@ -1,12 +1,8 @@ /* Knight Rider 2 * -------------- + * + * Array e uso dei cicli iterativi. * - * Reducing the amount of code using for(;;). - * - * - * (cleft) 2005 K3, Malmo University - * @author: David Cuartielles - * @hardware: David Cuartielles, Aaron Hallborg Schema semplificato: @@ -15,24 +11,25 @@ */ int pinArray[8] = {2, 3, 4, 5, 6, 7, 8, 9}; -int count = 0; int timer = 100; void setup(){ // we make all the declarations at once - for (count=0;count<9;count++) { + for (int count=0;count<9;count++) { pinMode(pinArray[count], OUTPUT); } } void loop() { - for (count=0;count<8;count++) { // 8 e' un numero magico + for (int count=0;count<8;count++) { // 8 e' un numero magico digitalWrite(pinArray[count], HIGH); delay(timer); digitalWrite(pinArray[count], LOW); delay(timer); } - for (count=8;count>=0;count--) { + +// Ciclo inverso: dall'alto in basso + for (int count=8;count>=0;count--) { digitalWrite(pinArray[count], HIGH); delay(timer); digitalWrite(pinArray[count], LOW); @@ -46,6 +43,16 @@ void loop() { 2. Come posso fare per uscire completamente dal loop? 3. 8 e' un numero magico: come posso evitarlo? +. +. +. +. +. +. +. +. +. +. . . . diff --git a/programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino b/programming/loops/loop_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino similarity index 100% rename from programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino rename to programming/loops/loop_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino diff --git a/programming/loops/loop_3_multi_led/loop_3_multi_led.ino b/programming/loops/loop_3_multi_led/loop_3_multi_led.ino deleted file mode 100644 index bb7e7ce..0000000 --- a/programming/loops/loop_3_multi_led/loop_3_multi_led.ino +++ /dev/null @@ -1,45 +0,0 @@ -/* - 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 - */ - -int timer = 100; // The higher the number, the slower the timing. - -void setup() { - // use a for loop to initialize each pin as an output: - for (int thisPin = 2; thisPin <= 9; thisPin++) { - pinMode(thisPin, OUTPUT); - } -} - -void loop() { - // loop from the lowest pin to the highest: - for (int thisPin = 2; thisPin < 9; thisPin++) { - // turn the pin on: - digitalWrite(thisPin, HIGH); - delay(timer); - // turn the pin off: - digitalWrite(thisPin, LOW); - } - - // loop from the highest pin to the lowest: - for (int thisPin = 9; thisPin > 2; thisPin--) { - // turn the pin on: - digitalWrite(thisPin, HIGH); - delay(timer); - // turn the pin off: - digitalWrite(thisPin, LOW); - } -} diff --git a/programming/loops/loop_5_multi_led_random/loop_5_multi_led_random.ino b/programming/loops/loop_3_multi_led_random/loop_3_multi_led_random.ino similarity index 100% rename from programming/loops/loop_5_multi_led_random/loop_5_multi_led_random.ino rename to programming/loops/loop_3_multi_led_random/loop_3_multi_led_random.ino diff --git a/programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino b/programming/loops/match_4_for_loop/match_4_for_loop.ino similarity index 97% rename from programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino rename to programming/loops/match_4_for_loop/match_4_for_loop.ino index 94b3e3a..d338658 100644 --- a/programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino +++ b/programming/loops/match_4_for_loop/match_4_for_loop.ino @@ -52,11 +52,14 @@ void loop() { // put your main code here, to run repeatedly: } } +// Reset routine Serial.println("Counter resetted."); // serial staff digitalWrite(RED, HIGH); delay(WAIT); count++ ; totalRun++ ; + +// Final Exit routine if (totalRun == MAXRUN) { Serial.println("10 runs done, exit program."); digitalWrite(RED, HIGH); diff --git a/programming/loops/loop_match_2_while_loop/loop_match_2_while_loop.ino b/programming/loops/match_5_while_loop/match_5_while_loop.ino similarity index 100% rename from programming/loops/loop_match_2_while_loop/loop_match_2_while_loop.ino rename to programming/loops/match_5_while_loop/match_5_while_loop.ino -- 2.39.2