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));
36 randomSeed(analogRead(0)); // Rilevazione di un valore esterno
37 // per scegliere il primo elemento del pseudorandom generators
41 // print a random number from 0 to 8
42 randNumber = random(8);
44 Serial.print("Accensione pin n. ");
45 Serial.println(randNumber);
46 digitalWrite(ledPins[randNumber], HIGH);
49 digitalWrite(ledPins[randNumber], LOW);
51 if (randNumber == 0) {
60 // Esegue un pattern con i led
62 Serial.println(">>> Rainbow! <<<");
63 for (int thisPin = 0; thisPin < sizeof(ledPins); thisPin++) {
65 digitalWrite(ledPins[thisPin], HIGH);
68 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);