]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/millis/millis.ino
Clean up multitasking, bottoni con pooling e interrupts
[sketchbook_andrea] / basic / blinks / millis / millis.ino
1 /* Blink without Delay - only led
2  
3  Turns on and off a light emitting diode(LED) connected to a digital  
4  pin, without using the delay() function.  This means that other code
5  can run at the same time without being interrupted by the LED code.
6  
7 Schema: https://lab.piffa.net/schemi/circuito_led_bb.png
8  
9  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
10  */
11
12 const int led = 13;      // Primo LED
13               
14 unsigned long previousMillis = 0;        // Ultimo aggiornamento
15 unsigned long interval = 1000;           // Pausa tra i lampeggi
16
17 void setup() {
18   pinMode(led, OUTPUT);      
19 }
20
21 void loop()
22 {
23   if (millis() - previousMillis >= interval) {
24     previousMillis += interval ;
25
26     digitalWrite(led, !digitalRead(led));
27   }
28 }