-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.ino
59 lines (50 loc) · 1.42 KB
/
Functions.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
void resetData() {
//This are the start values of each channal
// Throttle is 0 in order to stop the motors
//127 is the middle value of the 10ADC.
data.throttle = 127;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
data.AUX1 = 0;
data.AUX2 = 0;
}
int mapConstrain(int input, int in_min, int in_max, int out_min, int out_max, int center, int deadzone_low, int deadzone_high, int fine) {
int mappedValue;
if (input >= deadzone_low && input <= deadzone_high) {
return center;
} else if (input < deadzone_low) {
mappedValue = map(input, in_min, deadzone_low, out_min, center);
} else if (input > deadzone_low) {
mappedValue = map(input, in_max, deadzone_high, out_max, center);
}
mappedValue = mappedValue + fine;
return constrain(mappedValue, min(out_min, out_max), max(out_min, out_max));
}
float lowPassFilter(float previousValue, float newValue, float alpha) {
return (alpha * newValue) + ((1 - alpha) * previousValue);
}
void startMelody() {
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
delay(40);
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
}
void melody1() {
digitalWrite(buzzer, HIGH);
delay(50);
digitalWrite(buzzer, LOW);
}
void BlinkLed(int time, int count) {
for (int i = 1; i <= count; i++) {
digitalWrite(led, LOW);
delay(time);
digitalWrite(led, HIGH);
if (i != count) {
delay(time);
}
}
}