Hello fine humans,
I am trying to read a PWM signal from a hobby receiver. I have code which successfully reads it when I only read one pin, but it no longer works after reading multiple. Why is that and how do I fix it?
It works in this configuration:
void setup() {
Serial.begin(9600);
}
void loop() {
int throttle = pulseIn(3, HIGH, 25000);
throttle = map(throttle, 1100, 1900, 0, 180);
Serial.println(throttle);
delay(10);
}
Even if I do this, (adding another input but before the desired input) it still works:
void setup() {
Serial.begin(9600);
}
void loop() {
int rollIn = pulseIn(5, HIGH, 25000);
rollIn = map(rollIn, 1100, 1900, 0, 180);
int throttle = pulseIn(3, HIGH, 25000);
throttle = map(throttle, 1100, 1900, 0, 180);
Serial.println(throttle);
delay(10);
}
But as soon as they are flipped it doesn't work:
void setup() {
Serial.begin(9600);
}
void loop() {
int throttle = pulseIn(3, HIGH, 25000);
throttle = map(throttle, 1100, 1900, 0, 180);
int rollIn = pulseIn(5, HIGH, 25000);
rollIn = map(rollIn, 1100, 1900, 0, 180);
Serial.println(throttle);
delay(10);
}
I am using an Arduino nano and a spektrum receiver.
Any help would be much appreciated!
Kevin
SOLVED:
This was simply solved by moving the code into my main program. I don't know what changed as the lines of code are still the same, but it works now. The great Arduino gods have smiled down upon me today.