Advertisement
KarolKita

Untitled

Mar 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * CE D7
  3.  * CSN D8
  4.  * SCK D13
  5.  * MO D11
  6.  * MI D12
  7. */
  8.  
  9. #include <PWM.h>
  10. #include <SPI.h>
  11. #include <nRF24L01.h>
  12. #include <RF24.h>
  13. #include <Servo.h>
  14.  
  15. #define CE_PIN   7
  16. #define CSN_PIN 8
  17.  
  18.  
  19. #define go 9
  20. #define L 2
  21. #define P 4
  22.  
  23. //int32_t frequency = 2500;
  24.  
  25. // NOTE: the "LL" at the end of the constant is "LongLong" type
  26. const uint64_t pipe = 0xE8E8F0F0E1LL;
  27.  
  28. RF24 radio(CE_PIN, CSN_PIN);
  29.  
  30. Servo Turn;
  31.  
  32. //---( Declare Variables )---/
  33. int joystick[3];
  34. int forward = 0;
  35. int reverse = 0;
  36. int sterering = 90;
  37. int fail = 0;
  38.  
  39. void setup()
  40. {
  41.   delay(1000);
  42. //  InitTimersSafe();
  43. //  bool success = SetPinFrequencySafe(9, frequency);
  44.   radio.begin();
  45.   radio.setDataRate(RF24_250KBPS);
  46.   radio.openReadingPipe(1, pipe);
  47.   radio.startListening();
  48.   Turn.attach(3);
  49.   pinMode(P, OUTPUT);
  50.   digitalWrite(P, 0);
  51.   pinMode(L, OUTPUT);
  52.   digitalWrite(L, 0);
  53. }
  54.  
  55. void loop(){
  56.   if (radio.available()){
  57.     {
  58.       radio.read(joystick, sizeof(joystick));
  59.       sterering = map(joystick[1], 286, 757, 35, 145);
  60.       Turn.write(sterering);
  61.       if(joystick[2] == 0){
  62.       if(460 < joystick[0] < 550){
  63.         forward = 0;
  64.       }
  65.       if(550 < joystick[0]){
  66.         forward = map(joystick[0], 550, 800, 0, 255);
  67.         digitalWrite(L, LOW);
  68.         digitalWrite(P, HIGH);
  69.       }
  70.       else if(450 > joystick[0]){
  71.         forward = map(joystick[0], 460, 200, 0, 255);
  72.         digitalWrite(P, LOW);
  73.         digitalWrite(L, HIGH);
  74.       }
  75.       analogWrite(go, forward);
  76.       fail = 0;
  77.     }
  78.     if(joystick[2] == 1){
  79.       digitalWrite(P, LOW);
  80.       digitalWrite(L, LOW);
  81.       analogWrite(go, 0);
  82.     }
  83.    }
  84.   }
  85. /*  else
  86.   {
  87.     fail++;
  88.     if (fail > 200){
  89.     analogWrite(go, 0);
  90.     analogWrite(L, 0);
  91.     sterering = 90;
  92.     }
  93.    ]
  94. */
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement