Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Required to use SPI. */
- #include <SPI.h>
- /* Libraries to talk to the NRF2401 */
- #include "nRF24L01.h"
- #include "RF24.h"
- /* Sets up the RF24 library a different way
- for the Arduino Mega 2560. */
- #if defined(__AVR_ATmega2560__)
- RF24 radio(53,48);
- #else
- RF24 radio(9,10);
- #endif
- /* Defines the structure of the data
- that will be transmitted. */
- struct data {
- byte start;
- byte left;
- byte right;
- byte finish;
- };
- /* Give a friendly name to the struct */
- typedef struct data Packet;
- /* Create an instance of the struct. */
- Packet myData = {0, 0, 0, 0};
- /* Easy way to set the left and right values. */
- void setThrottleData(byte left, byte right){
- myData.left = left;
- myData.right = right;
- }
- void setup(){
- /* Sets up the NRF library */
- radio.begin();
- /* MUST BE OPPOSITE THE RECEIVER!!! */
- radio.openWritingPipe(0xF0F0F0F0E1LL);
- radio.openReadingPipe(1,0xF0F0F0F0D2LL);
- /* Set the radio up to transmit. */
- radio.stopListening();
- }
- /* Hold the test values to send to the receiver. */
- byte left = 0x00;
- byte right = 0x00;
- void loop(){
- /* Increment and decrement for tests */
- setThrottleData(left++,right--);
- /* Send the entire packet */
- if(radio.write(&myData, sizeof(Packet)) == false){
- Serial.println("Error sending packet");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement