Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <inttypes.h>
- #define RC_MIN 900
- #define RC_MAX 2100
- volatile uint16_t rcValue[8] = {1502, 1502, 1502, 1502, 1502, 1502, 1502, 1502}; // interval [1000;2000]
- //uint8_t rcChannel[6] = {18,17,16,15,14,8};
- uint8_t rcChannel[6] = {18,19,20,21,22,23};
- uint32_t rcEdgeTime[6];
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- setup_rc_input2();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- for(int i = 0; i < 6; i++)
- {
- Serial.print(rcValue[i]);
- Serial.print(" ");
- }
- Serial.println();
- delay(100);
- }
- void setup_rc_input2() {
- if (rcChannel[0]) {
- pinMode(rcChannel[0],INPUT);
- attachInterrupt(rcChannel[0], RCServiceR0, RISING);
- }
- if (rcChannel[1]) {
- pinMode(rcChannel[1],INPUT);
- attachInterrupt(rcChannel[1], RCServiceR1, RISING);
- }
- if (rcChannel[2]) {
- pinMode(rcChannel[2],INPUT);
- attachInterrupt(rcChannel[2], RCServiceR2, RISING);
- }
- if (rcChannel[3]) {
- pinMode(rcChannel[3],INPUT);
- attachInterrupt(rcChannel[3], RCServiceR3, RISING);
- }
- if (rcChannel[4]) {
- pinMode(rcChannel[4],INPUT);
- attachInterrupt(rcChannel[4], RCServiceR4, RISING);
- }
- if (rcChannel[5]) {
- pinMode(rcChannel[5],INPUT);
- attachInterrupt(rcChannel[5], RCServiceR5, RISING);
- }
- if (rcChannel[6]) {
- pinMode(rcChannel[6],INPUT);
- attachInterrupt(rcChannel[6], RCServiceR6, RISING);
- }
- }
- void RCServiceR0() {
- rcEdgeTime[0]= micros();
- attachInterrupt(rcChannel[0], RCServiceF0, FALLING);
- }
- void RCServiceF0() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[0], RCServiceR0, RISING);
- sei();
- current = current - rcEdgeTime[0];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[0] = current;
- }
- }
- void RCServiceR1() {
- rcEdgeTime[1]= micros();
- attachInterrupt(rcChannel[1], RCServiceF1, FALLING);
- }
- void RCServiceF1() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[1], RCServiceR1, RISING);
- sei();
- current = current - rcEdgeTime[1];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[1] = current;
- }
- }
- void RCServiceR2() {
- rcEdgeTime[2]= micros();
- attachInterrupt(rcChannel[2], RCServiceF2, FALLING);
- }
- void RCServiceF2() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[2], RCServiceR2, RISING);
- sei();
- current = current - rcEdgeTime[2];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[2] = current;
- }
- }
- void RCServiceR3() {
- rcEdgeTime[3]= micros();
- attachInterrupt(rcChannel[3], RCServiceF3, FALLING);
- }
- void RCServiceF3() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[3], RCServiceR3, RISING);
- sei();
- current = current - rcEdgeTime[3];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[3] = current;
- }
- }
- void RCServiceR4() {
- rcEdgeTime[4]= micros();
- attachInterrupt(rcChannel[4], RCServiceF4, FALLING);
- }
- void RCServiceF4() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[4], RCServiceR4, RISING);
- sei();
- current = current - rcEdgeTime[4];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[4] = current;
- }
- }
- void RCServiceR5() {
- rcEdgeTime[5]= micros();
- attachInterrupt(rcChannel[5], RCServiceF5, FALLING);
- }
- void RCServiceF5() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[5], RCServiceR5, RISING);
- sei();
- current = current - rcEdgeTime[5];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[5] = current;
- }
- }
- void RCServiceR6() {
- rcEdgeTime[6]= micros();
- attachInterrupt(rcChannel[6], RCServiceF6, FALLING);
- }
- void RCServiceF6() {
- uint32_t current= micros();
- attachInterrupt(rcChannel[6], RCServiceR6, RISING);
- sei();
- current = current - rcEdgeTime[6];
- if (current >= RC_MIN && current <= RC_MAX) {
- rcValue[6] = current;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement