Advertisement
KarolKita

Untitled

Mar 17th, 2019
80
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; // Define the transmit pipe
  27.  
  28. //---( Declare objects )---/
  29. RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
  30.  
  31. Servo Turn;
  32.  
  33. //---( Declare Variables )---/
  34. int joystick[3];
  35. int forward = 0;
  36. int reverse = 0;
  37. int sterering = 90;
  38. int fail = 0;
  39.  
  40. void setup()
  41. {
  42.   delay(1000);
  43. //  InitTimersSafe();
  44. //  bool success = SetPinFrequencySafe(9, frequency);
  45.   radio.begin();
  46.   radio.setDataRate(RF24_250KBPS);
  47.   radio.openReadingPipe(1, pipe);
  48.   radio.startListening();
  49.   Turn.attach(6);
  50.   pinMode(P, OUTPUT);
  51.   digitalWrite(P, 0);
  52.   pinMode(L, OUTPUT);
  53.   digitalWrite(L, 0);
  54. }
  55.  
  56. void loop(){
  57.   if (radio.available()){
  58.     {
  59.       radio.read(joystick, sizeof(joystick));
  60.       sterering = map(joystick[1], 286, 757, 35, 145);
  61.       Turn.write(sterering);
  62.       if(joystick[2] == 0){
  63.       if(460 < joystick[0] < 550){
  64.         forward = 0;
  65.       }
  66.       if(550 < joystick[0]){
  67.         forward = map(joystick[0], 550, 800, 0, 255);
  68.         digitalWrite(L, LOW);
  69.         digitalWrite(P, HIGH);
  70.       }
  71.       else if(450 > joystick[0]){
  72.         forward = map(joystick[0], 460, 200, 0, 255);
  73.         digitalWrite(P, LOW);
  74.         digitalWrite(L, HIGH);
  75.       }
  76.       analogWrite(go, forward);
  77.       fail = 0;
  78.     }
  79.     if(joystick[2] == 1){
  80.       digitalWrite(P, LOW);
  81.       digitalWrite(L, LOW);
  82.       analogWrite(go, 0);
  83.     }
  84.    }
  85.   }
  86. /*  else
  87.   {
  88.     fail++;
  89.     if (fail > 200){
  90.     analogWrite(go, 0);
  91.     analogWrite(L, 0);
  92.     sterering = 90;
  93.     }
  94.    ]
  95. */
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement