Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // L298N - Version: Latest
- #include <SPI.h>
- #include <nRF24L01.h>
- #include <RF24.h>
- #define jB1 5 // Joystick button 1
- #define jB2 4 // Joystick button 2
- #define b1 3 // Button 1
- #define b2 2 // Button 2
- #define b3 6 // Button 3
- #define b4 9 // Button 4
- RF24 radio(7, 8); // nRF24L01 (CE, CSN)
- const byte address[6] = "00001"; // Address
- // Max size of this struct is 32 bytes - NRF24L01 buffer limit
- struct Data_Package {
- byte j1PotX;
- byte j1PotY;
- byte j2PotX;
- byte j2PotY;
- byte button1;
- byte button2;
- byte button3;
- byte button4;
- };
- Data_Package data; //Create a variable with the above structure
- void setup() {
- Serial.begin(115200);
- Serial.println("receiver");
- radio.begin();
- radio.openWritingPipe(address);
- radio.setPALevel(RF24_PA_MAX);
- radio.setDataRate(RF24_250KBPS);
- radio.stopListening();
- }
- void loop() {
- data.j1PotX = analogRead(A5); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
- data.j1PotY = analogRead(A4);
- data.j2PotX = analogRead(A2);
- data.j2PotY = analogRead(A1);
- // Read all digital inputs
- data.button1 = digitalRead(b1);
- data.button2 = digitalRead(b2);
- data.button3 = digitalRead(b3);
- data.button4 = digitalRead(b4);
- radio.write(&data, sizeof(Data_Package)); // Write and send the data to the receiver
- Serial.println(data.j1PotX);
- Serial.println(data.j1PotY);
- Serial.println(data.j2PotX);
- Serial.println(data.j2PotY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement