Advertisement
GozuMezu

SMARS - transmitter

Jan 12th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.85 KB | Software | 0 0
  1. #include <SPI.h>
  2. #include <nRF24L01.h>
  3. #include <RF24.h>
  4.  
  5. int XPin = A0;
  6. int YPin = A1;
  7. int ButtonPin = A3;
  8.  
  9. int Array[3];
  10.  
  11. RF24 radio(8, 9);  // CE, CSN
  12. const byte address[6] = "00001";
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.  
  17.   pinMode(XPin, INPUT);
  18.   pinMode(YPin, INPUT);
  19.   pinMode(ButtonPin, INPUT_PULLUP);
  20.  
  21.   radio.begin();
  22.   radio.openWritingPipe(address);
  23.   radio.setPALevel(RF24_PA_MIN);
  24.   radio.stopListening();
  25.  
  26.   Serial.println("It has begun");
  27. }
  28.  
  29. void loop() {
  30.  
  31.   Array[0] = analogRead(XPin);
  32.   Array[1] = analogRead(YPin);
  33.   if (digitalRead(ButtonPin) == HIGH) {
  34.     Array[2] = 0;
  35.   }
  36.   else {
  37.     Array[2] = 1;
  38.   }
  39.  
  40.   radio.write(&Array, sizeof(Array));
  41.  
  42.   Serial.print("X: ");
  43.   Serial.println(Array[0]);
  44.   Serial.print("Y: ");
  45.   Serial.println(Array[1]);
  46.   Serial.print("Btn: ");
  47.   Serial.println(Array[2]);
  48.  
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement