Created
June 17, 2017 18:16
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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