]> git.piffa.net Git - sketchbook_andrea/blob - advanced_projects/interrupts/base/base.ino
interrupts
[sketchbook_andrea] / advanced_projects / interrupts / base / base.ino
1 /*
2    Interrupt base
3    
4    Utilizzo di un interrupt ala Arduino per intercettare
5    la pressione di un bottone.
6
7    Un momentary switch e' collegato in PULL UP al PIN D2
8    La Interrupt Service Routine reazioneISR viene associata all'interrupt 0
9    che reagisce al passaggio di stato 5v -> 0v del PIN D2
10
11    La pressione del bottone causa l'accensione del bottone
12    che viene spento periodicamente ogni 3 secondi nel loop,
13    il delay non pregiudica la percezione dell'evento.
14
15 Schema: https://www.arduino.cc/en/uploads/Tutorial/inputPullupButton.png
16    
17  */
18
19 int ledPin = 13; 
20
21 void setup()
22 {
23   pinMode(ledPin, OUTPUT);
24   pinMode(2, INPUT_PULLUP);
25   attachInterrupt(0, reazioneISR, FALLING); // 0 e' l'interrupt numero 0
26       // connesso al PIN D2, l'interrupt 1 e' connesso al PIN D3
27       // eventoAttivo : nome della funzione da richiamare
28       // per un ISRs e' sempre VOID
29       // LOW | RISING | FALLIN | CHANGE | HIGH
30 }
31
32 void loop()
33 {
34   // Varie altre cose che da cui non dipende la gestione dell'interrupt
35   delay(3000);
36   digitalWrite(ledPin,LOW);
37 }
38
39 void reazioneISR() // Sempre VOID
40 {
41   digitalWrite(ledPin, HIGH);
42 }