-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmillis_basic_demo.ino
58 lines (46 loc) · 1.27 KB
/
millis_basic_demo.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ---------------------------------------------
// millis_basic_demo.ino
// ---------------------------------------------
// License: The Unlicense, Public Domain.
// Author: Koepel
// 2019 january 23
// ---------------------------------------------
//
// millis_basic_demo.ino
//
// Running three different things with millis().
// The serial monitor is used to show the three different things.
//
unsigned long previousMillisDot;
const unsigned long intervalDot = 200;
unsigned long previousMillisHello;
const unsigned long intervalHello = 1600;
unsigned long previousMillisRandom;
unsigned long intervalRandom = 1000;
void setup()
{
Serial.begin( 9600);
Serial.println();
Serial.println( "The sketch has started");
}
void loop()
{
unsigned long currentMillis = millis();
if( currentMillis - previousMillisDot >= intervalDot)
{
previousMillisDot = currentMillis;
Serial.print( ".");
}
if( currentMillis - previousMillisHello >= intervalHello)
{
previousMillisHello = currentMillis;
Serial.println();
Serial.print( "Hello");
}
if( currentMillis - previousMillisRandom >= intervalRandom)
{
previousMillisRandom = currentMillis;
intervalRandom = (unsigned long) random( 500, 5000);
Serial.print( "Random");
}
}