X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=basic%2Fbuttons%2Fblink_6_interrupt%2Fblink_6_interrupt.ino;fp=basic%2Fbuttons%2Fblink_6_interrupt%2Fblink_6_interrupt.ino;h=7ddf386d0c9c51191fe6ac5860e5c36478169999;hp=0000000000000000000000000000000000000000;hb=e4de8b95aa9b8019b3fff9416918a4840aae46b5;hpb=98f12e9ba20d5b505b1b6506569e31af9ac3ba89 diff --git a/basic/buttons/blink_6_interrupt/blink_6_interrupt.ino b/basic/buttons/blink_6_interrupt/blink_6_interrupt.ino new file mode 100644 index 0000000..7ddf386 --- /dev/null +++ b/basic/buttons/blink_6_interrupt/blink_6_interrupt.ino @@ -0,0 +1,45 @@ +/* + Blink v1 + + Accensione e spegnimanto di due LED utilizzando un interrupt: + un interrupt associato al PIN del bottone sollecita una ISR routine + che puo' essere richiamata in ogni momento a prescindere + da cosa il microprocessore sta facendo nel loop. + + Nota: per togliere l'effetto bouncing del bottone: + - https://www.arduino.cc/en/tutorial/debounce + vedi esercizio: sketchbook_andrea/advanced_projects/interrupts/debounce/debounce.ino +- https://lab.piffa.net/sketchbook_andrea/advanced_projects/interrupts/debounce/debounce.ino + + */ + +// Pin 13 ha un LED collegato di default +const int ledA = 13; +const int ledB = 12; //Secondo LED, con resistenza +const int pausa = 5000; + +void setup() { + // Inizializziamo il PIN 13 come OUTPUT + pinMode(ledA, OUTPUT); + pinMode(ledB, OUTPUT); + + pinMode(2, INPUT_PULLUP); + attachInterrupt(0, reazioneISR, FALLING); // 0 e' l'interrupt numero 0 + // connesso al PIN D2, l'interrupt 1 e' connesso al PIN D3 + // eventoAttivo : nome della funzione da richiamare + // per un ISRs e' sempre VOID + // LOW | RISING | FALLIN | CHANGE | HIGH +} + +void loop() { + digitalWrite(ledA, HIGH); + delay(pausa); + digitalWrite(ledA, LOW); + delay(pausa); +} + +void reazioneISR() // Sempre VOID +{ + digitalWrite(ledB, !digitalRead(ledB)); +} +