Created
June 13, 2022 06:20
-
-
Save haumacher/00ae8dedaf72527acbe51e7a5d0f8d06 to your computer and use it in GitHub Desktop.
Arduino sketch converting PPM input to FMS-PIC serial data flying in a flight simulator with a remote control
This file contains 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
#include <PPMReader.h> | |
const byte ppmInputPin = 3; | |
const byte channels = 6; | |
const unsigned PPM_MIN = 1000; | |
const unsigned PPM_RANGE = 1000; | |
const unsigned FMS_MAX = 254; | |
PPMReader ppm(ppmInputPin, channels); | |
void setup() { | |
Serial.begin(19200); | |
} | |
void loop() { | |
// Start byte. | |
Serial.write(255); | |
for (byte channel = 1; channel <= channels; ++channel) { | |
unsigned raw = ppm.latestValidChannelValue(channel, 0); | |
outputValue(raw); | |
} | |
delay(50); | |
} | |
void outputValue(int raw) { | |
unsigned long offset = max(0, raw - PPM_MIN); | |
unsigned value = min(FMS_MAX, offset * FMS_MAX / PPM_RANGE); | |
Serial.write(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment