-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm365extender.ino
77 lines (63 loc) · 1.94 KB
/
m365extender.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
68
69
70
71
72
73
74
75
76
77
#include "Arrow.h"
#include "Buzzer.h"
const uint32_t flashPin = 10;
const uint32_t interruptFlashPin = 0;
const uint32_t buzzerPin = 11;
const uint32_t interruptBuzzerPin = 1;
const uint32_t arrowPinL = 12;
const uint32_t interruptPinL = 2;
const uint32_t arrowPinR = 13;
const uint32_t interruptPinR = 3;
const uint32_t intervalArrow = 500;
const Arrow left = Arrow(arrowPinL, intervalArrow);
const Arrow right = Arrow(arrowPinR, intervalArrow);
uint32_t pitches[] = {NOTE_G4, NOTE_E4, NOTE_C4, NOTE_NO, NOTE_C4, NOTE_NO, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_NO, NOTE_F4, NOTE_NO, NOTE_G4, NOTE_NO, NOTE_G4, NOTE_NO, NOTE_G4, NOTE_NO, NOTE_E4, NOTE_NO};
uint32_t times[] = {150, 150, 300, 10, 300, 10, 150, 150, 150, 10, 150, 10, 300, 10, 300, 10, 300, 10, 300, 1500};
const Buzzer buzzer = Buzzer(buzzerPin, pitches, times, 20);
void interF() {
byte state = digitalRead(interruptFlashPin);
if (state == HIGH) {
digitalWrite(flashPin, HIGH);
} else {
digitalWrite(flashPin, LOW);
}
}
void interB() {
byte state = digitalRead(interruptBuzzerPin);
if (state == HIGH) {
buzzer.execStart();
} else {
buzzer.execStop();
}
}
void interL() {
byte state = digitalRead(interruptPinL);
if (state == HIGH) {
left.execStart();
} else {
left.execStop();
}
}
void interR() {
byte state = digitalRead(interruptPinR);
if (state == HIGH) {
right.execStart();
} else {
right.execStop();
}
}
void setup() {
setupInter(interruptPinL, interL, CHANGE);
setupInter(interruptPinR, interR, CHANGE);
setupInter(interruptBuzzerPin, interB, CHANGE);
setupInter(interruptFlashPin, interF, CHANGE);
}
void loop() {
left.exec();
right.exec();
buzzer.exec();
}
void setupInter(uint32_t pin, void (*interFun)(void), uint32_t mode){
pinMode(pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(pin), interFun, mode);
}