Hi Group,
I'm pretty new to the Arduino world but I am an engineer so I'm familiar with programming. I am however having a problem figuring out a piece of code. The goal of the code is to take two signals coming from two separate potentiometers, compare them, and then using the greater of the two to generate an ESC signal to drive an RC motor (or a servo signal, same thing). I started with a piece of code for a single input to generate a servo output, which worked fine for driving my motor. Here it is:
#include <Servo.h>
Servo ESC; // create servo object to control the ESC
int potValue; // value from the analog pin
void setup() {
// Attach the ESC on pin 9
ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds)
}
void loop() {
potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
potValue = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo library (value between 0 and 180)
ESC.write(potValue); // Send the signal to the ESC
}
So then I tried to modify it to do the comparison of two separate potentiometers and use the greater of the two values to generate the ESC signal. Here it is:
#include <Servo.h>
Servo ESC; // create servo object to control the ESC
int potValue; // calculated value of the greatest value between potvalue1 and potvalue2
int potValue1; // value from the analog pin A0 "hand throttle"
int potValue2; // value from the analog pin A1 "foot throttle"
void setup() {
// Attach the ESC on pin 9
ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds)
}
void loop() {
potValue1 = analogRead(A0); // reads the value of potentiometer1 (value between 0 and 1023)
potValue2 = analogRead(A1); // reads the value of potentiometer2 (value between 0 and 1023)
if (potValue1 > potValue2) digitalWrite(potValue, potValue1); //if the hand throttle is greater than the foot throttle then use the hand throttle
if (potValue2 > potValue1) digitalWrite(potValue, potValue2); //if the foot throttle is greater than the hand throttle then use the foot throttle
if (potValue1 = potValue2) digitalWrite(potValue, potValue1); //if both throttles are equal then use the hand throttle by default
potValue = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo library (value between 0 and 180)
ESC.write(potValue); // Send the signal to the ESC
}
Problem is it doesn't work. Neither pot changes the output signal at all. I'm sure it's a rookie mistake but I can't seem to see it. Anyone with experienced eyes, if you could take a look I would greatly appreciate it.
Thanks!