File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33PPMEncoder ppmEncoder;
44
55void PPMEncoder::begin (uint8_t pin) {
6- begin (pin, PPM_DEFAULT_CHANNELS);
6+ begin (pin, PPM_DEFAULT_CHANNELS, false );
77}
88
99void PPMEncoder::begin (uint8_t pin, uint8_t ch) {
10+ begin (pin, ch, false );
11+ }
12+
13+ void PPMEncoder::begin (uint8_t pin, uint8_t ch, boolean inverted) {
1014 cli ();
1115
16+ // Store on/off-State in variable to avoid another if in timing-critical interrupt
17+ onState = (inverted) ? HIGH : LOW;
18+ offState = (inverted) ? LOW : HIGH;
19+
1220 pinMode (pin, OUTPUT);
13- digitalWrite (pin, LOW );
21+ digitalWrite (pin, offState );
1422
1523 state = true ;
1624 elapsedUs = 0 ;
@@ -45,11 +53,11 @@ void PPMEncoder::interrupt() {
4553 TCNT1 = 0 ;
4654
4755 if (state) {
48- digitalWrite (outputPin, HIGH );
56+ digitalWrite (outputPin, onState );
4957 OCR1A = PPM_PULSE_LENGTH_uS * 2 ;
5058
5159 } else {
52- digitalWrite (outputPin, LOW );
60+ digitalWrite (outputPin, offState );
5361
5462 if (currentChannel >= numChannels) {
5563 currentChannel = 0 ;
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ class PPMEncoder {
2222 uint8_t currentChannel;
2323 byte outputPin;
2424 boolean state;
25+
26+ uint8_t onState;
27+ uint8_t offState;
28+
2529
2630 public:
2731 static const uint16_t MIN = 1000 ;
@@ -32,6 +36,7 @@ class PPMEncoder {
3236
3337 void begin (uint8_t pin);
3438 void begin (uint8_t pin, uint8_t ch);
39+ void begin (uint8_t pin, uint8_t ch, boolean inverted);
3540
3641 void interrupt ();
3742};
You can’t perform that action at this time.
0 commit comments