Advertisement
Guest User

PPM_RC

a guest
Nov 15th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. #include <inttypes.h>
  2.  
  3.  
  4. #define RC_MIN 900
  5. #define RC_MAX 2100
  6. volatile uint16_t rcValue[8] = {1502, 1502, 1502, 1502, 1502, 1502, 1502, 1502}; // interval [1000;2000]
  7. //uint8_t rcChannel[6] = {18,17,16,15,14,8};
  8. uint8_t rcChannel[6] = {18,19,20,21,22,23};
  9. uint32_t rcEdgeTime[6];
  10.  
  11. void setup() {
  12.   // put your setup code here, to run once:
  13.   Serial.begin(9600);
  14.  
  15.   setup_rc_input2();
  16. }
  17.  
  18. void loop() {
  19.   // put your main code here, to run repeatedly:
  20.   for(int i = 0; i < 6; i++)
  21.   {
  22.     Serial.print(rcValue[i]);
  23.     Serial.print("    ");
  24.   }
  25.  
  26.   Serial.println();
  27.  
  28.   delay(100);
  29. }
  30.  
  31. void setup_rc_input2() {
  32.   if (rcChannel[0]) {
  33.     pinMode(rcChannel[0],INPUT);
  34.     attachInterrupt(rcChannel[0], RCServiceR0, RISING);
  35.   }
  36.   if (rcChannel[1]) {
  37.     pinMode(rcChannel[1],INPUT);
  38.     attachInterrupt(rcChannel[1], RCServiceR1, RISING);
  39.   }
  40.   if (rcChannel[2]) {
  41.     pinMode(rcChannel[2],INPUT);
  42.     attachInterrupt(rcChannel[2], RCServiceR2, RISING);
  43.   }
  44.   if (rcChannel[3]) {
  45.     pinMode(rcChannel[3],INPUT);
  46.     attachInterrupt(rcChannel[3], RCServiceR3, RISING);
  47.   }
  48.   if (rcChannel[4]) {
  49.     pinMode(rcChannel[4],INPUT);
  50.     attachInterrupt(rcChannel[4], RCServiceR4, RISING);
  51.   }
  52.   if (rcChannel[5]) {
  53.     pinMode(rcChannel[5],INPUT);
  54.     attachInterrupt(rcChannel[5], RCServiceR5, RISING);
  55.   }
  56.   if (rcChannel[6]) {
  57.     pinMode(rcChannel[6],INPUT);
  58.     attachInterrupt(rcChannel[6], RCServiceR6, RISING);
  59.   }
  60. }
  61.  
  62. void RCServiceR0() {
  63.   rcEdgeTime[0]= micros();
  64.   attachInterrupt(rcChannel[0], RCServiceF0, FALLING);
  65. }
  66.  
  67. void RCServiceF0() {
  68.   uint32_t current= micros();
  69.   attachInterrupt(rcChannel[0], RCServiceR0, RISING);
  70.   sei();
  71.   current = current - rcEdgeTime[0];
  72.   if (current >= RC_MIN && current <= RC_MAX) {
  73.       rcValue[0] = current;
  74.   }
  75. }
  76.  
  77. void RCServiceR1() {
  78.   rcEdgeTime[1]= micros();
  79.   attachInterrupt(rcChannel[1], RCServiceF1, FALLING);
  80. }
  81.  
  82. void RCServiceF1() {
  83.   uint32_t current= micros();
  84.   attachInterrupt(rcChannel[1], RCServiceR1, RISING);
  85.   sei();
  86.   current = current - rcEdgeTime[1];
  87.   if (current >= RC_MIN && current <= RC_MAX) {
  88.       rcValue[1] = current;
  89.   }
  90. }
  91.  
  92. void RCServiceR2() {
  93.   rcEdgeTime[2]= micros();
  94.   attachInterrupt(rcChannel[2], RCServiceF2, FALLING);
  95. }
  96.  
  97. void RCServiceF2() {
  98.   uint32_t current= micros();
  99.   attachInterrupt(rcChannel[2], RCServiceR2, RISING);
  100.   sei();
  101.   current = current - rcEdgeTime[2];
  102.   if (current >= RC_MIN && current <= RC_MAX) {
  103.       rcValue[2] = current;
  104.   }
  105. }
  106.  
  107. void RCServiceR3() {
  108.   rcEdgeTime[3]= micros();
  109.   attachInterrupt(rcChannel[3], RCServiceF3, FALLING);
  110. }
  111.  
  112. void RCServiceF3() {
  113.   uint32_t current= micros();
  114.   attachInterrupt(rcChannel[3], RCServiceR3, RISING);
  115.   sei();
  116.   current = current - rcEdgeTime[3];
  117.   if (current >= RC_MIN && current <= RC_MAX) {
  118.       rcValue[3] = current;
  119.   }
  120. }
  121.  
  122. void RCServiceR4() {
  123.   rcEdgeTime[4]= micros();
  124.   attachInterrupt(rcChannel[4], RCServiceF4, FALLING);
  125. }
  126.  
  127. void RCServiceF4() {
  128.   uint32_t current= micros();
  129.   attachInterrupt(rcChannel[4], RCServiceR4, RISING);
  130.   sei();
  131.   current = current - rcEdgeTime[4];
  132.   if (current >= RC_MIN && current <= RC_MAX) {
  133.       rcValue[4] = current;
  134.   }
  135. }
  136.  
  137. void RCServiceR5() {
  138.   rcEdgeTime[5]= micros();
  139.   attachInterrupt(rcChannel[5], RCServiceF5, FALLING);
  140. }
  141.  
  142. void RCServiceF5() {
  143.   uint32_t current= micros();
  144.   attachInterrupt(rcChannel[5], RCServiceR5, RISING);
  145.   sei();
  146.   current = current - rcEdgeTime[5];
  147.   if (current >= RC_MIN && current <= RC_MAX) {
  148.       rcValue[5] = current;
  149.   }
  150. }
  151.  
  152. void RCServiceR6() {
  153.   rcEdgeTime[6]= micros();
  154.   attachInterrupt(rcChannel[6], RCServiceF6, FALLING);
  155. }
  156.  
  157. void RCServiceF6() {
  158.   uint32_t current= micros();
  159.   attachInterrupt(rcChannel[6], RCServiceR6, RISING);
  160.   sei();
  161.   current = current - rcEdgeTime[6];
  162.   if (current >= RC_MIN && current <= RC_MAX) {
  163.       rcValue[6] = current;
  164.   }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement