forked from LuSeKa/HoverBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmDecoder.ino
31 lines (28 loc) · 1.03 KB
/
pwmDecoder.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
// Interrupt callbacks to measure the pwm duty cycle
void decodePwm_1() {
static unsigned long riseTime = micros(); // initialize riseTime
if (digitalRead(PWM_CHANNEL_1) == 1) { // the signal has risen
riseTime = micros(); // save the rise time
}
else { // the signal has fallen
pwmDutyCycle_steering = micros() - riseTime; // compute the duration of the high pulse
}
}
void decodePwm_2() {
static unsigned long riseTime = micros(); // initialize riseTime
if (digitalRead(PWM_CHANNEL_2) == 1) { // the signal has risen
riseTime = micros(); // save the rise time
}
else { // the signal has fallen
pwmDutyCycle_throttle = micros() - riseTime; // compute the duration of the high pulse
}
}
void decodePwm_3() {
static unsigned long riseTime = micros(); // initialize riseTime
if (digitalRead(PWM_CHANNEL_3) == 1) { // the signal has risen
riseTime = micros(); // save the rise time
}
else { // the signal has fallen
pwmDutyCycle_mode = micros() - riseTime; // compute the duration of the high pulse
}
}