-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmetronome.ino
48 lines (39 loc) · 1.19 KB
/
metronome.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
#include "Arduino.h"
#include "metronome.h"
Metronome metronome;
// the metronome will call this function every 1/24th of a quarter note.
void ppqCallback()
{
static int quarters = 0;
static int beat = 0;
digitalWriteFast(2, HIGH); // every 1/24th quarter
delayMicroseconds(1);
digitalWriteFast(2, LOW);
if (quarters == 0) // every quarter
{
digitalWriteFast(3, HIGH);
delayMicroseconds(1);
digitalWriteFast(3, LOW);
}
if (beat == 0) // every beat
{
digitalWriteFast(4, HIGH);
delayMicroseconds(1);
digitalWriteFast(4, LOW);
}
quarters = (quarters+1) % 24;
beat = (beat + 1) % 96;
}
void setup()
{
for(int pin: {2,3,4, LED_BUILTIN}){ // we need pin 2,3,4 for the debugging output in ppqCallback
pinMode(pin, OUTPUT);
}
metronome.begin(ppqCallback, 0, 1, 200); // attach an encoder at pins 0,1 to the metronome and limit its range to 200
// tell the metronome to call "handleTimer" on each 1/24th quarter note
}
void loop()
{
digitalToggleFast(LED_BUILTIN); // heart beat
delay(500);
}