X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=multitasking%2FBlinkWithoutDelay_8_struct_pointer%2FBlinkWithoutDelay_8_struct_pointer.ino;h=9e36670b9b65bbe63cd7714500b168b3e6067699;hb=HEAD;hp=635642d50afe9f299189304c9ac547add9affa55;hpb=90f3116fa09ed583c137d1df423b9913f55522fa;p=sketchbook_andrea diff --git a/multitasking/BlinkWithoutDelay_8_struct_pointer/BlinkWithoutDelay_8_struct_pointer.ino b/multitasking/BlinkWithoutDelay_8_struct_pointer/BlinkWithoutDelay_8_struct_pointer.ino index 635642d..9e36670 100644 --- a/multitasking/BlinkWithoutDelay_8_struct_pointer/BlinkWithoutDelay_8_struct_pointer.ino +++ b/multitasking/BlinkWithoutDelay_8_struct_pointer/BlinkWithoutDelay_8_struct_pointer.ino @@ -20,7 +20,7 @@ struct blinkLed { long interval ; // milliseconds di intervallo nel lampeggiare long previousMillis ; //precedente cambio di stato }; -// Instanziamo i due led dalla struttur +// Instanziamo i due led dalla struttura blinkLed ledA = { 13 , LOW , 1000, 0 }; blinkLed ledB = { @@ -40,11 +40,14 @@ void loop() //////////////// // Funzioni -void lightLed(struct blinkLed *temp) { // temp ora e' un pointer e non una struttura autonoma: pass by reference (not by value) +void lightLed(struct blinkLed *temp) { // temp ora e' un pointer e non una copia autonoma: pass by reference (not by value) +// Si noti che la funzione e' ora void dato che non deve tornare a passare nulla al loop: molto +piu' semplice (una sorta di polimorfismo). + // Illumina il ledA secondo un intervallo passato come argomento - if(millis() - (*temp).previousMillis > (*temp).interval) { // l'operatore punto ha priorita' maggiore rispetto al pointer asterisco - (*temp).previousMillis = millis(); + if(millis() - (*temp).previousMillis >= (*temp).interval) { // l'operatore punto ha priorita' maggiore rispetto al pointer asterisco + (*temp).previousMillis += (*temp).interval ; // if the LED is off turn it on and vice-versa: temp->ledState = !temp->ledState ; // Forma contratta, deference operator: temp->ledState == (*temp).ledState