Guest User

Untitled

a guest
Aug 2nd, 2015
278
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <nRF905.h>
  2. #include <SPI.h>
  3. #include <Servo.h>
  4.  
  5. Servo myservo1;
  6.  
  7. void setup()
  8. {
  9.     // Start up
  10.     nRF905_init();
  11.  
  12.     // Put into receive mode
  13.     nRF905_receive();
  14.  
  15.     Serial.begin(9600);
  16.  
  17.     Serial.println(F("Server started"));
  18. }
  19.  
  20. void loop()
  21. {
  22.     Serial.println(F("Waiting for data..."));
  23.  
  24.     // Make buffer for data
  25.     byte buffer[NRF905_MAX_PAYLOAD];
  26.  
  27.     // Wait for data
  28.     while(!nRF905_getData(buffer, sizeof(buffer)));
  29.  
  30.     // Put back into receive mode
  31.     nRF905_receive();
  32.  
  33.     Serial.println(F("Got data"));
  34.  
  35.     // Read values from payload
  36.     int vals[5];
  37.     for(byte i=0;i<5;i++)
  38.     {
  39.         vals[i] = buffer[i * 2] | (buffer[(i * 2) + 1]<<8);
  40.     }
  41.  
  42.     Serial.println(vals[0]);
  43.  
  44.     int val = vals[1];
  45.     if(val < 450)
  46.         val = 450;
  47.     else if(val > 770)
  48.         val = 770;
  49.  
  50.     byte servoVal = map(val, 770, 450, 200, 0);
  51.     myservo1.write(servoVal);
  52. }
RAW Paste Data