-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmillis_rhythm.ino
67 lines (56 loc) · 1.19 KB
/
millis_rhythm.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
59
60
61
62
63
64
65
66
67
// ---------------------------------------------
// millis_rhythm.ino
// ---------------------------------------------
// License: The Unlicense, Public Domain.
// Author: Koepel
// 2019 january 23
// ---------------------------------------------
//
// millis with a rhythm.
//
// Make a led blink with a specific rhythm, using millis.
//
const int ritme_table[] =
{
160, 200, // 160 ms on, 200 ms off
140, 200,
120, 200,
100, 200,
80, 1000,
80, 120,
80, 120,
80, 1000,
1000, 500,
};
unsigned long previousMillis;
int index = 0;
const int ledPin = 13;
void setup()
{
pinMode( ledPin, OUTPUT);
// The table starts with the led on.
// After 160 ms it will be turned off.
digitalWrite( ledPin, HIGH);
previousMillis = millis();
}
void loop()
{
unsigned long currentMillis = millis();
if( currentMillis - previousMillis >= ritme_table[index])
{
previousMillis = currentMillis;
if( index % 2 == 0) // check if the index is an even number
{
digitalWrite( ledPin, LOW);
}
else
{
digitalWrite( ledPin, HIGH);
}
index++;
if( index >= sizeof(ritme_table) / sizeof(int))
{
index = 0;
}
}
}