My objective here is to read a pwm signal from an rc receiver. I want to read 3 seperate signals, and use them to turn led's on or off depending on read value.
The following code is where Im at, however it doesnt work correctly. When I turn my first channel on it lights the led, when the second channel triggers its led it turns on, but when the value is reached that should turn it off it does not turn off. I am very new to coding and not sure what to do. Any help would be greatly appreciated.
byte PWM_PIN1 = 1;
byte PWM_PIN2 = 2; // input from rcvr throttle to digi pin 2
byte PWM_PIN3 = 3; // input from rcvr gear to digi pin 3
int pwm_value1;
int pwm_value2;
int pwm_value3;
const int ledPin8 = 8;
const int ledPin9 = 9; // to brake light led
const int ledPin10 = 10; // to driving lights relay
void setup() {
pinMode(PWM_PIN1, INPUT);
pinMode(PWM_PIN2, INPUT);
pinMode(PWM_PIN3, INPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
Serial.begin(115200);
}
void loop() {
pwm_value1 = pulseIn(PWM_PIN1, HIGH);
pwm_value2 = pulseIn(PWM_PIN2, HIGH);
pwm_value3 = pulseIn(PWM_PIN3, HIGH);
if (pwm_value1 > 1470) {
digitalWrite(ledPin8, LOW);
Serial.println(pwm_value1);
}
else if (pwm_value2 < 1465) {
digitalWrite(ledPin9, HIGH); // turn brake light on
Serial.println(pwm_value2);
}
else if (pwm_value3 > 1470) {
digitalWrite(ledPin10, HIGH);
Serial.println(pwm_value3);
}
else {
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
}
}