Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #define IBUS_BUFFSIZE 32 // Max iBus packet size (2 byte header, 14 channels x 2 bytes, 2 byte checksum)
- #define IBUS_MAXCHANNELS 10
- static uint8_t ibusIndex = 0;
- static uint8_t ibus[IBUS_BUFFSIZE] = {0};
- static uint16_t rcValue[IBUS_MAXCHANNELS];
- void setup()
- {
- Serial.begin(115200);
- digitalWrite(13, HIGH); //Flash on rx update
- Serial.println(“setup done!”);
- }
- void loop()
- {
- readRx();
- UpdateOutput();
- }
- void UpdateOutput()
- {
- }
- void readRx()
- {
- uint8_t i;
- if (Serial.available())
- {
- uint8_t val = Serial.read();
- // Look for 0x2040 as start of packet
- if (ibusIndex == 0 && val != 0x20) {
- return;
- }
- if (ibusIndex == 1 && val != 0x40) {
- ibusIndex = 0;
- return;
- }
- if (ibusIndex < IBUS_BUFFSIZE) ibus[ibusIndex] = val;
- ibusIndex++;
- if (ibusIndex == IBUS_BUFFSIZE)
- {
- digitalWrite(13,LOW);
- }
- ibusIndex = 0;
- rcValue[0] = (ibus[ 3] << 8) + ibus[ 2];
- rcValue[1] = (ibus[ 5] << 8) + ibus[ 4];
- rcValue[2] = (ibus[ 7] << 8) + ibus[ 6];
- rcValue[3] = (ibus[ 9] << 8) + ibus[ 8];
- rcValue[4] = (ibus[11] << 8) + ibus[10];
- rcValue[5] = (ibus[13] << 8) + ibus[12];
- rcValue[6] = (ibus[15] << 8) + ibus[14];
- rcValue[7] = (ibus[17] << 8) + ibus[16];
- rcValue[8] = (ibus[19] << 8) + ibus[18];
- rcValue[9] = (ibus[21] << 8) + ibus[20];
- digitalWrite(13,HIGH);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement