4 Generazione di un numero casuale per modificare il flusso del programma.
10 * LEDs from pins 2 through 9 to ground
13 - http://lab.piffa.net/schemi/8_led_single_res_bb.png
14 - http://lab.piffa.net/schemi/8_led_single_res_schem.png
16 http://www.arduino.cc/en/Tutorial/ForLoop
19 byte ledPins[8] = { // Domanda: cosa succede se uso int?
22 int timer = 100; // Pausa per far brillare i LED
27 // use a for loop to initialize each pin as an output:
28 for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
29 pinMode(ledPins[thisPin], OUTPUT);
30 Serial.print("Inizializzato pin n. ");
31 Serial.println( thisPin);
34 Serial.print("Dimesione array: ");
35 Serial.println(sizeof(ledPins));
37 randomSeed(analogRead(0)); // Rilevazione di un valore esterno
38 // per scegliere il primo elemento del pseudorandom generators
42 // print a random number from 0 to 7
43 randNumber = random(8);
45 Serial.print("Accensione pin n. ");
46 Serial.println(randNumber);
47 digitalWrite(ledPins[randNumber], HIGH);
50 digitalWrite(ledPins[randNumber], LOW);
52 if (randNumber == 0) {
61 // Esegue un pattern con i led
63 Serial.println(">>> Rainbow! <<<");
64 // loop from the lowest pin to the highest:
65 for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
67 digitalWrite(ledPins[thisPin], HIGH);
70 digitalWrite(ledPins[thisPin], LOW);
73 // loop from the highest pin to the lowest:
74 for (int thisPin = sizeof(ledPins) -1 ; thisPin > 0; thisPin--) {
75 // ><<turn the pin on:
76 digitalWrite(ledPins[thisPin], HIGH);
79 digitalWrite(ledPins[thisPin], LOW);