-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.h
88 lines (79 loc) · 2.08 KB
/
tools.h
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
78
79
80
81
82
83
84
85
86
87
88
int unbouncedStartSwitch() {
int tmp = digitalRead(startSwitch);
if ( (millis() - lastDebounceTimeStart) > debounceDelay) {
lastDebounceTimeStart = millis();
buttonStateStart = tmp;
return tmp;
}
else {
return buttonStateStart;
}
}
int unbouncedRotarySwitch() {
int tmp = digitalRead(outputSW);
if ( (millis() - lastDebounceTimeRotarySW) > debounceDelay) {
lastDebounceTimeRotarySW = millis();
buttonStateRotarySW = tmp;
return tmp;
}
else {
return buttonStateRotarySW;
}
}
void doEncoderA()
{
//if ( rotating ) delay (1); // wait a little until the bouncing is done
if( digitalRead(encoderPinA) != A_set ) { // debounce once more
A_set = !A_set;
// adjust counter + if A leads B
if ( A_set && !B_set ) {
if ((configActive == theCurrent) && (torqCurrent < torqCurrentMax)) {
torqCurrent += 10;
}
else if ((configActive == theAfterburner) && (afterburner < afterburnerMax)) {
afterburner +=1;
}
else if (configActive == theBuzzer) {
buzzerActive = 1;
}
}
//rotating = false; // no more debouncing until loop() hits again
}
}
void doEncoderB(){
//if ( rotating ) delay (1);
if( digitalRead(encoderPinB) != B_set ) {
B_set = !B_set;
// adjust counter - 1 if B leads A
if ( B_set && !A_set ) {
if ((configActive == theCurrent) && (torqCurrent > torqCurrentMin)){
torqCurrent -= 10;
}
else if ((configActive == theAfterburner) && (afterburner > afterburnerMin)) {
afterburner -=1;
}
else if (configActive == theBuzzer) {
buzzerActive = 0;
}
}
//rotating = false;
}
}
void playBuzzer(playBuzzerToneEnum playThis) {
switch (playThis) {
case theOK:
if (buzzerActive) {tone(buzzer, 1000);}
delay(50);
noTone(buzzer);
delay(50);
if (buzzerActive) {tone(buzzer, 1000);}
delay(50);
noTone(buzzer);
break;
case theError:
if (buzzerActive) {tone(buzzer, 100);}
delay(1000);
noTone(buzzer);
break;
}
}