Skip to content

Instantly share code, notes, and snippets.

@werneckpaiva
Created May 21, 2020 20:20
Show Gist options
  • Save werneckpaiva/62f0e9d62fbc1dc647233dd694950974 to your computer and use it in GitHub Desktop.
Save werneckpaiva/62f0e9d62fbc1dc647233dd694950974 to your computer and use it in GitHub Desktop.
#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);
}
@JustinDoubs
Copy link

JustinDoubs commented Jul 16, 2022

I think i found this on your Post: https://dronebotworkshop.com/radio-control-arduino-car/ where you use this sketch with the arduino mega pin 19 (serial rx 1) im trying to read the ibus data with an arduino uno. I cannont work out how to do this is there a difference between the rx pins on the uno and mega?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment