I'm using arduino Mega and IBUS flysky transmitter.
The sketch should be receive the command from flysky and print value to Serial monitor.
Please the follow code doesn't work why?
#include <IBusBM.h>
IBusBM ibusRc;
HardwareSerial& ibusRcSerial = Serial1;
HardwareSerial& debugSerial = Serial;
void setup() {
debugSerial.begin(74880);
ibusRc.begin(ibusRcSerial);
}
// Read the number of a given channel and convert to the range provided.
// If the channel is off, return the default value
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue){
uint16_t ch = ibusRc.readChannel(channelInput);
if (ch < 100) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
}
// Red the channel and return a boolean value
bool redSwitch(byte channelInput, bool defaultValue){
int intDefaultValue = (defaultValue)? 100: 0;
int ch = readChannel(channelInput, 0, 100, intDefaultValue);
return (ch > 50);
}
void loop() {
for (byte i = 0; i<4; i++){
int value = readChannel(i, -100, 100, 0);
debugSerial.print("Ch");
debugSerial.print(i + 1);
debugSerial.print(": ");
debugSerial.print(value);
debugSerial.print(" ");
}
debugSerial.print("Ch5: ");
debugSerial.print(redSwitch(4, false));
debugSerial.println();
delay(10);
}