I'm pretty new to programming Arduino, so I'm not sure what I'm doing wrong. I have an RC receiver hooked up to an Arduino Mega 2560 and when I read the values from the channels, all I'm getting is gibberish. There aren't any number values being returned. I know certain pins on the board do certain things, so I tried finding which pins to connect the receiver too but everything is giving me gibberish. Any help would be greatly appreciated.
#define CH1 4 // Right Stick Right/Left
#define CH2 5 // Right Stick Up/Down
#define CH3 6 // Left Stick Up/Down
#define CH4 7 // Left Stick Right/Left
#define CH5 8 // Switch A
#define CH6 9 // Switch B
#define CH7 10 // Switch E (3 way)
#define CH8 11 // Not used currently
#define CH9 12 // Not used currently
#define CH10 13 // Not used currently
int ch1Value; // Right Stick Right/Left
int ch2Value; // Right Stick Up/Down
int ch3Value; // Left Stick Up/Down
int ch4Value; // Left Stick Right/Left
bool ch5Value; // Switch A
bool ch6Value; // Switch B
int ch7Value; // Switch E (3 way)
//int ch8Value;
//bool ch9Value;
//bool ch10Value;
void setup() {
Serial.begin(9600);
// Remote Reciever Setup
pinMode(CH1, INPUT);
pinMode(CH2, INPUT);
pinMode(CH3, INPUT);
pinMode(CH4, INPUT);
pinMode(CH5, INPUT);
pinMode(CH6, INPUT);
pinMode(CH7, INPUT);
pinMode(CH8, INPUT);
pinMode(CH9, INPUT);
pinMode(CH10, INPUT);
}
void loop() {
// Get values for each channel
ch1Value = readChannel(CH1, -100, 100, 0);
ch2Value = readChannel(CH2, -100, 100, 0);
ch3Value = readChannel(CH3, -100, 100, 0);
ch4Value = readChannel(CH4, -100, 100, 0);
ch5Value = readSwitch(CH5, false);
ch6Value = readSwitch(CH6, false);
ch7Value = readChannel(CH7, -100, 100, 0);
/*
Serial.print("CH1: " + ch1Value);
Serial.print(", CH2: " + ch2Value);
Serial.print(", CH3: " + ch3Value);
Serial.print(", CH4: " + ch4Value);
Serial.print(", CH5: " + ch5Value);
Serial.print(", CH6: " + ch6Value);
Serial.println(", CH7: " + ch7Value);
*/
Serial.println("CH1: " + pulseIn(CH1, HIGH, 30000));
delay(1000);
}
int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue)
{
int ch = pulseIn(channelInput, HIGH, 30000);
if (ch < minLimit) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
} //int readChannel()
// Read the switch channel and return a boolean value
bool readSwitch(byte channelInput, bool defaultValue)
{
int intDefaultValue = (defaultValue)? 100: 0;
int ch = readChannel(channelInput, 0, 100, intDefaultValue);
return (ch > 50);
} // bool readSwitch()