Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <CanSatKit.h>
  2.  
  3. using namespace CanSatKit;
  4.  
  5. #define L_POT A0
  6. #define R_POT A1
  7.  
  8. bool led_state = false;
  9. const int led_pin = 13;
  10.  
  11. Radio radio(Pins::Radio::ChipSelect,
  12.             Pins::Radio::DIO0,
  13.             433.0,
  14.             Bandwidth_125000_Hz,
  15.             SpreadingFactor_7,
  16.             CodingRate_4_8);
  17.  
  18. byte motVal[2] = { 0x00 , 0x00 };
  19.  
  20. void setup() {
  21.   SerialUSB.begin(115200);
  22.   pinMode(led_pin, OUTPUT);
  23.   pinMode(L_POT, INPUT);
  24.   pinMode(R_POT, INPUT);
  25.  
  26.   radio.begin();
  27. }
  28.  
  29. void loop() {
  30.   if (radio.tx_fifo_empty())
  31.   {
  32.     digitalWrite(led_pin, led_state);
  33.     led_state = !led_state;
  34.  
  35.     motVal[0] = (byte)(analogRead(L_POT) / 4);
  36.     motVal[1] = (byte)(analogRead(R_POT) / 4);
  37.     radio.transmit(motVal, 2);
  38.  
  39.     SerialUSB.println(String(motVal[0]) + " " + String(motVal[1]));
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement