Lab_interaccio/2016/nrf24l01/rgb_RX/rgb_RX.ino

102 lines
2.4 KiB
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
/* YourDuinoStarter Example: nRF24L01 Receive Joystick values
- WHAT IT DOES: Receives data from another transceiver with
2 Analog values from a Joystick or 2 Potentiometers
Displays received values on Serial Monitor
- SEE the comments after "//" on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
- V1.00 11/26/13
Based on examples at http://www.bajdi.com/
Questions: terry@yourduino.com */
/*-----( Import needed libraries )-----*/
#include <SPI.h>
//#include <nRF24L01.h>
//#include <RF24.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN 2
#define CSN_PIN 11
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
uint8_t rgb[4]; // 2 element array holding Joystick readings
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(57600);
delay(4000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
printf_begin();
radio.setAutoAck(0);
radio.setPayloadSize(4);
radio.openReadingPipe(1,pipe);
radio.startListening();
radio.printDetails();
delay(2000);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
// if ( radio.available() )
// {
// Serial.println("radio available");
// // Read the data payload until we've received everything
// bool done = false;
//// while (!done)
//// {
// // Fetch the data payload
// radio.read( rgb, sizeof(rgb) );
// analogWrite(5, rgb[1]);
// analogWrite(10, rgb[2]);
// analogWrite(9, rgb[3]);
//
// Serial.print("id = ");
// Serial.print(rgb[0]);
// Serial.print("\t");
// Serial.print(rgb[1]);
// Serial.print("\t");
// Serial.print(rgb[2]);
// Serial.print("\t");
// Serial.println(rgb[3]);
//
//
//// }
// }
// //else
// //{
// //Serial.println("No radio available");
// //}
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//NONE
//*********( THE END )***********