]> git.piffa.net Git - sketchbook_andrea/blob - basic/blinks/millis/millis.ino
Rover prima lezione
[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  
8 Schema: https://lab.piffa.net/schemi/circuito_led_bb.png
9  
10  
11  http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
12  */
13
14 // constants won't change. Used here to 
15 // set pin numbers:
16 const int led = 13;      // Primo LED
17
18               
19 unsigned long previousMillis = 0;        // will store last time LED was updated
20 unsigned long interval = 1000;           // interval at which to blink (milliseconds)
21
22 void setup() {
23   // set the digital pin as output:
24   pinMode(led, OUTPUT);      
25 }
26
27 void loop()
28 {
29   if (millis() - previousMillis >= interval) {
30     // Timestamp + timestamp = delta temporale
31     previousMillis += interval ;
32
33     digitalWrite(led, !digitalRead(led));
34   }
35 }