SHARE
TWEET

Untitled

a guest Aug 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <RHReliableDatagram.h>
  2. #include <RH_NRF24.h>
  3. #include <SPI.h>
  4.  
  5. #define joyV A0
  6. #define joyH A1
  7. #define CLIENT_ADDRESS 1
  8. #define SERVER_ADDRESS 2
  9.  
  10. int joyposV = 512;
  11. int joyposH = 512;
  12.  
  13. RH_NRF24 RadioDriver;
  14. RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);
  15.  
  16. uint8_t motorcontrol[3];
  17. uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
  18.  
  19. void setup() {
  20.   // put your setup code here, to run once:
  21.   pinMode(3,INPUT);
  22.   if(!RadioManager.init())
  23.   motorcontrol[2] = 0;
  24. }
  25.  
  26. void loop() {
  27.   // put your main code here, to run repeatedly:
  28.   joyposV = analogRead(joyV);
  29.   joyposH = analogRead(joyH);
  30.  
  31.   if(joyposV < 460){
  32.     motorcontrol[2] = 1;
  33.  
  34.     motorcontrol[0] = map(joyposV, 460, 0, 0, 255);
  35.     motorcontrol[1] = map(joyposV, 460, 0, 0, 255);
  36.   }
  37.   else if(joyposV > 564){
  38.     motorcontrol[2] = 0;
  39.  
  40.     motorcontrol[0] = map(joyposV, 564, 1023, 0, 255);
  41.     motorcontrol[1] = map(joyposV, 564, 1023, 0, 255);
  42.   }
  43.   else{
  44.     motorcontrol[0] = 0;
  45.     motorcontrol[1] = 0;
  46.     motorcontrol[2] = 0;
  47.   }
  48.  
  49.   if(joyposH < 460){
  50.     joyposH = map(joyposH, 460, 0, 0, 255);
  51.  
  52.     motorcontrol[0] = motorcontrol[0] - joyposH;
  53.     motorcontrol[1] = motorcontrol[1] + joyposH;
  54.  
  55.     if(motorcontrol[0] < 0)motorcontrol[0] = 0;
  56.     if(motorcontrol[1] > 255)motorcontrol[1] = 255;
  57.   }
  58.   else if(joyposH > 564){
  59.     joyposH = map(joyposH, 564, 1023, 0, 255);
  60.  
  61.     motorcontrol[0] = motorcontrol[0] + joyposH;
  62.     motorcontrol[1] = motorcontrol[1] - joyposH;
  63.  
  64.     if(motorcontrol[0] > 255)motorcontrol[0] = 255;
  65.     if(motorcontrol[1] < 0)motorcontrol[1] = 0;
  66.   }
  67.  
  68.   if(motorcontrol[0] < 8)motorcontrol[0] = 0;
  69.   if(motorcontrol[1] < 8)motorcontrol[1] = 0;
  70.  
  71.   if(RadioManager.sendtoWait(motorcontrol, sizeof(motorcontrol), SERVER_ADDRESS)){
  72.     uint8_t len = sizeof(buf);
  73.     uint8_t from;
  74.   }
  75.   delay(50);
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top