Last active
August 8, 2016 11:19
-
-
Save cirias/e612c3ff3a0e0420128e6f5e9ce98a83 to your computer and use it in GitHub Desktop.
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
#include "PinChangeInterrupt.h" | |
// Choose a valid PinChangeInterrupt pin of your Arduino board | |
#define pcintThrottle 12 // A4 | |
#define pcintAileron 13 // A5 | |
/* #define pcintThrottle 13 // A4 */ | |
volatile int thro_pwm_value = 0; | |
volatile int thro_prev_time = 0; | |
volatile int aile_pwm_value = 0; | |
volatile int aile_prev_time = 0; | |
void rising1(void); | |
void falling1(void); | |
void rising2(void); | |
void falling2(void); | |
void rising1(void) { | |
thro_prev_time = micros(); | |
/* Serial.println("rising1"); */ | |
attachPCINT(pcintThrottle, falling1, FALLING); | |
} | |
void falling1(void) { | |
thro_pwm_value = micros() - thro_prev_time; | |
/* Serial.println("falling1"); */ | |
attachPCINT(pcintThrottle, rising1, RISING); | |
} | |
void rising2(void) { | |
aile_prev_time = micros(); | |
Serial.println("rising2"); | |
attachPCINT(pcintThrottle, falling2, FALLING); | |
} | |
void falling2(void) { | |
aile_pwm_value = micros() - aile_prev_time; | |
Serial.println("falling2"); | |
attachPCINT(pcintThrottle, rising2, RISING); | |
} | |
void setup() { | |
// set pin to input with a pullup, led to output | |
pinMode(pcintThrottle, INPUT_PULLUP); | |
pinMode(pcintAileron, INPUT_PULLUP); | |
// Attach the new PinChangeInterrupt and enable event function below | |
/* attachPCINT(pcintThrottle, rising1, RISING); */ | |
/* attachPCINT(pcintThrottle, rising2, RISING); */ | |
attachPCINT(pcintAileron, rising2, RISING); | |
Serial.begin(115200); | |
} | |
void loop() { | |
/* Serial.print(thro_pwm_value); */ | |
/* Serial.print(" "); */ | |
/* Serial.println(aile_pwm_value); */ | |
/* delay(500); */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment