Skip to content

Instantly share code, notes, and snippets.

@zerotacg
Created June 17, 2017 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerotacg/02f9e74842964326cca83b608b136910 to your computer and use it in GitHub Desktop.
Save zerotacg/02f9e74842964326cca83b608b136910 to your computer and use it in GitHub Desktop.
simple unoptimized arduino code to read data from an rc receiver and send via serial
#define CHANNEL_0 14
#define CHANNEL_1 15
#define CHANNEL_2 16
uint16_t ch0;
uint16_t ch1;
uint16_t ch2;
void setup() {
Serial.begin(19200);
pinMode(CHANNEL_0, INPUT);
pinMode(CHANNEL_1, INPUT);
pinMode(CHANNEL_2, INPUT);
}
void loop() {
ch0 = pulseIn(CHANNEL_0,HIGH, 32000);
ch1 = pulseIn(CHANNEL_1,HIGH, 32000);
ch2 = pulseIn(CHANNEL_2,HIGH, 32000);
Serial.write(0xca);
Serial.write(0xfe);
writeChannel(ch0);
writeChannel(ch1);
writeChannel(ch2);
}
void writeChannel(uint16_t ch) {
Serial.write((ch >> 8) & 0xff);
Serial.write((ch) & 0xff);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment