X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=multitasking%2FBlinkWithoutDelay_7_struct%2FBlinkWithoutDelay_7_struct.ino;h=6f7517d00e697318334a4866b37cd7193f7ffef9;hb=e4de8b95aa9b8019b3fff9416918a4840aae46b5;hp=e72666285569423af9762ee8e6c6b2cc2966c32c;hpb=ad3aca9c8c8e24f1a1e0326ef5f027ab23b75712;p=sketchbook_andrea diff --git a/multitasking/BlinkWithoutDelay_7_struct/BlinkWithoutDelay_7_struct.ino b/multitasking/BlinkWithoutDelay_7_struct/BlinkWithoutDelay_7_struct.ino index e726662..6f7517d 100644 --- a/multitasking/BlinkWithoutDelay_7_struct/BlinkWithoutDelay_7_struct.ino +++ b/multitasking/BlinkWithoutDelay_7_struct/BlinkWithoutDelay_7_struct.ino @@ -1,7 +1,17 @@ /* Blink without Delay - Soluzione - Introdotto un argomento per la funzione che nodifica l'intervallo di lampeggio +Raggruppamento delle proprieta' dell'oggetto in uno struct. +Una funzione accetta e restituisce uno struct di questo tipo +facendo una "copy by value" (vedi esercizio con i pointers per +una "copy by reference"). + +Questo e' un esercizio avanzato: propedeutico a capire le basi +della programmazione a oggetti (suggerimento: +https://lab.piffa.net/sketchbook_andrea/RGB_LED/ + +e' piu' semplice dato che non usa pointers e references +non dovendo modificare in modo permanente nessuna variabile +dello struct). */ struct blinkLed { @@ -37,9 +47,9 @@ void loop() struct blinkLed lightLed(struct blinkLed temp) { // dataType tipo_di_struct nome_funzione(argomenti) // Illumina il ledA secondo un intervallo passato come argomento - if (millis() > temp.previousMillis + temp.interval) { // gli elementi dello struct sono accessibili tramite l'operatore [punto] + if (millis() - temp.previousMillis >= temp.interval) { // gli elementi dello struct sono accessibili tramite l'operatore [punto] // save the last time you blinked the LED - temp.previousMillis = millis(); + temp.previousMillis += temp.interval ; // if the LED is off turn it on and vice-versa: temp.ledState = !temp.ledState ; // Inverti il LED