KRITSADA

ATX2 Control Motor From 4 Channel RC Remote Control

Aug 20th, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. //************************************************
  2. // Control Motor From 4 Channel RC Remote Control
  3. // First Step 2 Channel Only
  4. //************************************************
  5. #include <ATX2.h>
  6. int A,X,Y,Z=0,CH1,CH2,CH3,CH4;
  7.  
  8. void setup(){
  9.  pinMode(26,INPUT);
  10.  pinMode(27,INPUT);
  11.  pinMode(28,INPUT);
  12.  pinMode(29,INPUT);
  13. }
  14. void loop(){
  15.  CH1 = pulseIn(27, HIGH, 25000);
  16.  CH2 = pulseIn(26, HIGH, 25000);
  17.  if(CH2>1600){
  18.    if(CH1<1400){
  19.        A=map(CH1,1000,1400,100,0);
  20.        motor(12,A);motor(34,-A);
  21.    }
  22.    else if (CH1>1600){
  23.        A=map(CH1,1600,1990,0,100);
  24.        motor(12,-A);motor(34,A);
  25.    }
  26.    else {
  27.        A=map(CH2,1600,1990,0,100);
  28.        motor(12,A);motor(34,A);
  29.    }
  30.  }
  31.   else if(CH2<1400){
  32.    if(CH1<1400){
  33.        A=map(CH1,1000,1400,100,0);
  34.        motor(12,-A);motor(34,A);
  35.    }
  36.    else if (CH1>1600){
  37.        A=map(CH1,1600,1990,0,100);
  38.        motor(12,A);motor(34,-A);
  39.    }
  40.    else {
  41.        A=map(CH2,1000,1400,100,0);
  42.        motor(12,-A);motor(34,-A);
  43.    }
  44.   }
  45.   else{
  46.       if(CH1<1400){
  47.        A=map(CH1,1000,1400,100,0);
  48.        motor(12,A);motor(34,-A);
  49.    }
  50.    else if (CH1>1600){
  51.        A=map(CH1,1600,1990,0,100);
  52.        motor(12,-A);motor(34,A);
  53.    }
  54.    else {
  55.        motor(12,0);motor(34,0);
  56.    }
  57.   }
  58.  CH3 = pulseIn(28, HIGH, 25000);
  59.  CH4 = pulseIn(29, HIGH, 25000);
  60. }
  61. void FD1 (int speed1,int speed2){
  62.   motor(12,speed1);
  63.   motor(34,speed1);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment