Advertisement
alexpetro000

Untitled

Dec 28th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4. #define CE_PIN   9
  5. #define CSN_PIN 10
  6. #define JOYSTICK_X A0
  7. #define JOYSTICK_Y A1
  8. #define JOYSTICK_Z A2
  9. const uint64_t pipe = 0xE8E8F0F0E1LL;
  10. RF24 radio(CE_PIN, CSN_PIN);
  11. int joystick[4];
  12. void setup()
  13.  
  14. {
  15.   Serial.begin(9600);
  16.   radio.begin();
  17.   radio.openWritingPipe(pipe);
  18.   pinMode(2, INPUT);
  19.   digitalWrite(2, HIGH);
  20.  }
  21.  
  22.  
  23. void loop()  
  24. {
  25.   joystick[0] = analogRead(JOYSTICK_X);
  26.   joystick[0] = map(joystick[0],0,1023,1,180);
  27.   joystick[1] = analogRead(JOYSTICK_Y);
  28.   joystick[2] = analogRead(JOYSTICK_Z);
  29.   joystick[2] = map(joystick[2],0,1023,1,180);
  30.   joystick[3] = digitalRead(2);
  31.  
  32.   radio.write( joystick, sizeof(joystick) );
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement