]> git.piffa.net Git - sketchbook_andrea/commitdiff
Merge branch 'master' of kim:/home/git/sketchbook_andrea
authorAndrea Manni <andrea@piffa.net>
Thu, 31 Mar 2016 13:40:07 +0000 (15:40 +0200)
committerAndrea Manni <andrea@piffa.net>
Thu, 31 Mar 2016 13:40:07 +0000 (15:40 +0200)
programming/loops/loop_0_rider/loop_0_rider.ino
programming/loops/loop_1_array_loop/loop_1_array_loop.ino
programming/loops/loop_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino [new file with mode: 0644]
programming/loops/loop_3_multi_led/loop_3_multi_led.ino [deleted file]
programming/loops/loop_3_multi_led_random/loop_3_multi_led_random.ino [new file with mode: 0644]
programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino [deleted file]
programming/loops/loop_5_multi_led_random/loop_5_multi_led_random.ino [deleted file]
programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino [deleted file]
programming/loops/loop_match_2_while_loop/loop_match_2_while_loop.ino [deleted file]
programming/loops/match_4_for_loop/match_4_for_loop.ino [new file with mode: 0644]
programming/loops/match_5_while_loop/match_5_while_loop.ino [new file with mode: 0644]

index 854f2252de572addc482ed065e6e87bdb28c8e48..1549668fe18496871bf47786b04adb20647f6c1b 100644 (file)
@@ -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(){
index 42871ef279b1c2192f11272cb45d3e393fc105f2..bb9662ecd1b1eaa0a60348ee77bbf2c5b064681d 100644 (file)
@@ -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: 
  */
 
 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_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino b/programming/loops/loop_2_array_loop_serial.ino/loop_2_array_loop_serial.ino.ino
new file mode 100644 (file)
index 0000000..3b5ddef
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+  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
+int timer = 100;           // Pausa per far brillare i LED
+
+void setup() {
+  Serial.begin(9600);
+  // use a for loop to initialize each pin as an output:
+  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++)  {
+    pinMode(ledPins[thisPin], OUTPUT);
+    Serial.print("Inizializzato pin n. ");
+    Serial.println(  thisPin);
+  }
+
+  Serial.print("Dimesione array: ");
+  Serial.println(sizeof(ledPins));
+}
+
+void loop() {
+  // loop from the lowest pin to the highest:
+  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
+    Serial.print("Accensione pin n. ");
+    Serial.println(thisPin);
+    // turn the pin on:
+    digitalWrite(ledPins[thisPin], HIGH);  
+    delay(timer);                  
+    // turn the pin off:
+    digitalWrite(ledPins[thisPin], LOW);    
+    // Debug
+
+  }
+
+  // loop from the highest pin to the lowest:
+  for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) {
+    Serial.print("Accensione pin n. "); // Gli array sono indicizzati da 0
+    Serial.println(thisPin);
+    // ><<turn the pin on:
+    digitalWrite(ledPins[thisPin], HIGH);
+    delay(timer);
+    // turn the pin off:
+    digitalWrite(ledPins[thisPin], LOW);
+
+  }
+}
+
+
+
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 (file)
index bb7e7ce..0000000
+++ /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_3_multi_led_random/loop_3_multi_led_random.ino b/programming/loops/loop_3_multi_led_random/loop_3_multi_led_random.ino
new file mode 100644 (file)
index 0000000..70cfc62
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+  Random Rainbow
+  
+  Generazione di un numero casuale per modificare il flusso del programma.
+  
+
+ 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
+int timer = 100;           // Pausa per far brillare i LED
+int randNumber ;
+
+void setup() {
+  Serial.begin(9600);
+  // use a for loop to initialize each pin as an output:
+  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++)  {
+    pinMode(ledPins[thisPin], OUTPUT);
+    Serial.print("Inizializzato pin n. ");
+    Serial.println(  thisPin);
+  }
+
+  Serial.print("Dimesione array: ");
+  Serial.println(sizeof(ledPins));
+  randomSeed(analogRead(0));  // Rilevazione di un valore esterno
+ // per scegliere il primo elemento del pseudorandom generators
+}
+
+void loop() {
+  // print a random number from 0 to 8
+  randNumber = random(8);
+  // turn the pin on:
+  Serial.print("Accensione pin  n. ");
+  Serial.println(randNumber);
+  digitalWrite(ledPins[randNumber], HIGH);  
+  delay(timer);                  
+  // turn the pin off:
+  digitalWrite(ledPins[randNumber], LOW);    
+
+  if (randNumber == 0) {
+    rainbow() ;
+  }
+}
+
+////////////////
+// Funzioni
+
+void rainbow() {
+  // Esegue un pattern con i led
+  
+  Serial.println(">>> Rainbow! <<<");
+  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
+    // turn the pin on:
+    digitalWrite(ledPins[thisPin], HIGH);  
+    delay(timer / 2);                  
+    // turn the pin off:
+    digitalWrite(ledPins[thisPin], LOW);    
+    // Debug
+
+  }
+
+  // loop from the highest pin to the lowest:
+  for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) {
+    // ><<turn the pin on:
+    digitalWrite(ledPins[thisPin], HIGH);
+    delay(timer / 3);
+    // turn the pin off:
+    digitalWrite(ledPins[thisPin], LOW);
+  }
+}
+
+
+
+
+
diff --git a/programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino b/programming/loops/loop_4_multi_led_array/loop_4_multi_led_array.ino
deleted file mode 100644 (file)
index 3b5ddef..0000000
+++ /dev/null
@@ -1,63 +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
- */
-
-byte ledPins[8] = {  // Domanda: cosa succede se uso int?
-  2,3,4,5,6,7,8,9} 
-; //Array
-int timer = 100;           // Pausa per far brillare i LED
-
-void setup() {
-  Serial.begin(9600);
-  // use a for loop to initialize each pin as an output:
-  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++)  {
-    pinMode(ledPins[thisPin], OUTPUT);
-    Serial.print("Inizializzato pin n. ");
-    Serial.println(  thisPin);
-  }
-
-  Serial.print("Dimesione array: ");
-  Serial.println(sizeof(ledPins));
-}
-
-void loop() {
-  // loop from the lowest pin to the highest:
-  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
-    Serial.print("Accensione pin n. ");
-    Serial.println(thisPin);
-    // turn the pin on:
-    digitalWrite(ledPins[thisPin], HIGH);  
-    delay(timer);                  
-    // turn the pin off:
-    digitalWrite(ledPins[thisPin], LOW);    
-    // Debug
-
-  }
-
-  // loop from the highest pin to the lowest:
-  for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) {
-    Serial.print("Accensione pin n. "); // Gli array sono indicizzati da 0
-    Serial.println(thisPin);
-    // ><<turn the pin on:
-    digitalWrite(ledPins[thisPin], HIGH);
-    delay(timer);
-    // turn the pin off:
-    digitalWrite(ledPins[thisPin], LOW);
-
-  }
-}
-
-
-
diff --git a/programming/loops/loop_5_multi_led_random/loop_5_multi_led_random.ino b/programming/loops/loop_5_multi_led_random/loop_5_multi_led_random.ino
deleted file mode 100644 (file)
index 70cfc62..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
-  Random Rainbow
-  
-  Generazione di un numero casuale per modificare il flusso del programma.
-  
-
- 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
-int timer = 100;           // Pausa per far brillare i LED
-int randNumber ;
-
-void setup() {
-  Serial.begin(9600);
-  // use a for loop to initialize each pin as an output:
-  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++)  {
-    pinMode(ledPins[thisPin], OUTPUT);
-    Serial.print("Inizializzato pin n. ");
-    Serial.println(  thisPin);
-  }
-
-  Serial.print("Dimesione array: ");
-  Serial.println(sizeof(ledPins));
-  randomSeed(analogRead(0));  // Rilevazione di un valore esterno
- // per scegliere il primo elemento del pseudorandom generators
-}
-
-void loop() {
-  // print a random number from 0 to 8
-  randNumber = random(8);
-  // turn the pin on:
-  Serial.print("Accensione pin  n. ");
-  Serial.println(randNumber);
-  digitalWrite(ledPins[randNumber], HIGH);  
-  delay(timer);                  
-  // turn the pin off:
-  digitalWrite(ledPins[randNumber], LOW);    
-
-  if (randNumber == 0) {
-    rainbow() ;
-  }
-}
-
-////////////////
-// Funzioni
-
-void rainbow() {
-  // Esegue un pattern con i led
-  
-  Serial.println(">>> Rainbow! <<<");
-  for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
-    // turn the pin on:
-    digitalWrite(ledPins[thisPin], HIGH);  
-    delay(timer / 2);                  
-    // turn the pin off:
-    digitalWrite(ledPins[thisPin], LOW);    
-    // Debug
-
-  }
-
-  // loop from the highest pin to the lowest:
-  for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) {
-    // ><<turn the pin on:
-    digitalWrite(ledPins[thisPin], HIGH);
-    delay(timer / 3);
-    // turn the pin off:
-    digitalWrite(ledPins[thisPin], LOW);
-  }
-}
-
-
-
-
-
diff --git a/programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino b/programming/loops/loop_match_2_for_loop/loop_match_2_for_loop.ino
deleted file mode 100644 (file)
index 94b3e3a..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Exercise 2, with a WHILE loop
-
- Test a random number agains a value: 
- a iteretive loop perform 255 runs to see if a random number in range 0-255
- is equal tothe target value of 200
- Light a led in case
- Light the other LED if a run of 255 test has gone
- Log the results (if success) trough serialport
- */
-
-// Data structure
-
-const byte GREEN   = 13  ; // LED for found value
-const byte RED     = 12 ;  // LEAD for restart
-
-const int TARGET   = 200 ;
-long randomNumber = 0L;
-
-// Staff
-const int WAIT = 1000 ;
-const int REST = 10 ;
-byte count = 0 ;
-const byte MAXRUN = 10 ;
-byte totalRun = 0 ;
-
-void setup() {
-  pinMode(RED,OUTPUT);     
-  pinMode(GREEN,OUTPUT); 
-  // Serial stuff
-  Serial.begin(9600);
-  Serial.println("Initializing random sequence, please wait for results.");
-
-  // Random stuff
-  randomSeed(analogRead(0)); // Random initializer
-
-}
-
-void loop() {  // put your main code here, to run repeatedly: 
-  digitalWrite(GREEN, LOW);  
-  digitalWrite(RED, LOW); 
-  // Serial.println(count);
-
-  for (count == 0; count < 255; count++ , delay(REST)) {
-    randomNumber = random(0,255); //Randoom value generated
-    if (randomNumber == TARGET) {  // When we catch the value
-      Serial.print("--> Match found! Counter was at: "); // serial message
-      Serial.println(count);
-      digitalWrite(GREEN, HIGH);
-      delay(WAIT * 5);
-      digitalWrite(GREEN, LOW);
-      count++ ;
-    }
-  }
-
-  Serial.println("Counter resetted.");   // serial staff
-  digitalWrite(RED, HIGH);
-  delay(WAIT);
-  count++ ;
-  totalRun++ ;
-  if (totalRun == MAXRUN) {
-    Serial.println("10 runs done, exit program.");
-    digitalWrite(RED, HIGH);
-    delay(WAIT);
-    exit(0);
-  }
-} 
-
diff --git a/programming/loops/loop_match_2_while_loop/loop_match_2_while_loop.ino b/programming/loops/loop_match_2_while_loop/loop_match_2_while_loop.ino
deleted file mode 100644 (file)
index 92d930d..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Exercise 2, with a WHILE loop and a Break statement:
-- http://arduino.cc/en/Reference/Break
-
- Test a random number agains a value: 
- a iteretive loop perform 255 runs to see if a random number in range 0-255
- is equal to the target value set to 200.
- Light a led in case
- Light the other LED if a run of 255 test has gone
- Log the results (if success) trough serialport
- */
-
-// Data structure
-
-const byte GREEN   = 13  ; // LED for found value
-const byte RED     = 12 ;  // LEAD for restart
-
-const int TARGET   = 200 ;
-long randomNumber = 0L;
-
-// Staff
-const int WAIT = 1000 ;
-const int REST = 10 ;
-byte count = 0 ;
-const byte MAXRUN = 10 ;
-byte totalRun = 0 ;
-
-void setup() {
-  pinMode(RED,OUTPUT);     
-  pinMode(GREEN,OUTPUT); 
-  // Serial stuff
-  Serial.begin(9600);
-  Serial.println("Initializing random sequence, please wait for results.");
-  randomSeed(analogRead(0)); // Random initializer
-}
-
-void loop() {  // put your main code here, to run repeatedly: 
-  digitalWrite(GREEN, LOW);  
-  digitalWrite(RED, LOW); 
-  // Serial.println(count);
-
-  while (count < 255) {
-    randomNumber = random(0,255); //Randoom value generated
-    Serial.print("|");
-    count++ ;  
-    delay(REST);
-    if (randomNumber == TARGET) {  // When we catch the value
-      Serial.println();
-      Serial.print("--> Match found! Counter was at: "); // serial message
-      Serial.println(count);
-      digitalWrite(GREEN, HIGH);
-      delay(WAIT);
-      count++ ;
-      break; // Interrompe il ciclo
-    }
-  }
-
-  Serial.println();
-  Serial.println("Counter resetted.");   // serial staff
-  count = 0;
-  digitalWrite(RED, HIGH);
-  delay(WAIT);
-  count++ ;
-  totalRun++ ;
-  if (totalRun == MAXRUN) {
-    Serial.println("10 runs done, exit program.");
-    digitalWrite(RED, HIGH);
-    delay(WAIT);
-    exit(0);
-  }
-} 
-
-
diff --git a/programming/loops/match_4_for_loop/match_4_for_loop.ino b/programming/loops/match_4_for_loop/match_4_for_loop.ino
new file mode 100644 (file)
index 0000000..d338658
--- /dev/null
@@ -0,0 +1,70 @@
+/* Exercise 2, with a WHILE loop
+
+ Test a random number agains a value: 
+ a iteretive loop perform 255 runs to see if a random number in range 0-255
+ is equal tothe target value of 200
+ Light a led in case
+ Light the other LED if a run of 255 test has gone
+ Log the results (if success) trough serialport
+ */
+
+// Data structure
+
+const byte GREEN   = 13  ; // LED for found value
+const byte RED     = 12 ;  // LEAD for restart
+
+const int TARGET   = 200 ;
+long randomNumber = 0L;
+
+// Staff
+const int WAIT = 1000 ;
+const int REST = 10 ;
+byte count = 0 ;
+const byte MAXRUN = 10 ;
+byte totalRun = 0 ;
+
+void setup() {
+  pinMode(RED,OUTPUT);     
+  pinMode(GREEN,OUTPUT); 
+  // Serial stuff
+  Serial.begin(9600);
+  Serial.println("Initializing random sequence, please wait for results.");
+
+  // Random stuff
+  randomSeed(analogRead(0)); // Random initializer
+
+}
+
+void loop() {  // put your main code here, to run repeatedly: 
+  digitalWrite(GREEN, LOW);  
+  digitalWrite(RED, LOW); 
+  // Serial.println(count);
+
+  for (count == 0; count < 255; count++ , delay(REST)) {
+    randomNumber = random(0,255); //Randoom value generated
+    if (randomNumber == TARGET) {  // When we catch the value
+      Serial.print("--> Match found! Counter was at: "); // serial message
+      Serial.println(count);
+      digitalWrite(GREEN, HIGH);
+      delay(WAIT * 5);
+      digitalWrite(GREEN, LOW);
+      count++ ;
+    }
+  }
+
+// 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);
+    delay(WAIT);
+    exit(0);
+  }
+} 
+
diff --git a/programming/loops/match_5_while_loop/match_5_while_loop.ino b/programming/loops/match_5_while_loop/match_5_while_loop.ino
new file mode 100644 (file)
index 0000000..92d930d
--- /dev/null
@@ -0,0 +1,73 @@
+/* Exercise 2, with a WHILE loop and a Break statement:
+- http://arduino.cc/en/Reference/Break
+
+ Test a random number agains a value: 
+ a iteretive loop perform 255 runs to see if a random number in range 0-255
+ is equal to the target value set to 200.
+ Light a led in case
+ Light the other LED if a run of 255 test has gone
+ Log the results (if success) trough serialport
+ */
+
+// Data structure
+
+const byte GREEN   = 13  ; // LED for found value
+const byte RED     = 12 ;  // LEAD for restart
+
+const int TARGET   = 200 ;
+long randomNumber = 0L;
+
+// Staff
+const int WAIT = 1000 ;
+const int REST = 10 ;
+byte count = 0 ;
+const byte MAXRUN = 10 ;
+byte totalRun = 0 ;
+
+void setup() {
+  pinMode(RED,OUTPUT);     
+  pinMode(GREEN,OUTPUT); 
+  // Serial stuff
+  Serial.begin(9600);
+  Serial.println("Initializing random sequence, please wait for results.");
+  randomSeed(analogRead(0)); // Random initializer
+}
+
+void loop() {  // put your main code here, to run repeatedly: 
+  digitalWrite(GREEN, LOW);  
+  digitalWrite(RED, LOW); 
+  // Serial.println(count);
+
+  while (count < 255) {
+    randomNumber = random(0,255); //Randoom value generated
+    Serial.print("|");
+    count++ ;  
+    delay(REST);
+    if (randomNumber == TARGET) {  // When we catch the value
+      Serial.println();
+      Serial.print("--> Match found! Counter was at: "); // serial message
+      Serial.println(count);
+      digitalWrite(GREEN, HIGH);
+      delay(WAIT);
+      count++ ;
+      break; // Interrompe il ciclo
+    }
+  }
+
+  Serial.println();
+  Serial.println("Counter resetted.");   // serial staff
+  count = 0;
+  digitalWrite(RED, HIGH);
+  delay(WAIT);
+  count++ ;
+  totalRun++ ;
+  if (totalRun == MAXRUN) {
+    Serial.println("10 runs done, exit program.");
+    digitalWrite(RED, HIGH);
+    delay(WAIT);
+    exit(0);
+  }
+} 
+
+