Hello all,
I'm doing an Arduino project with 3 devices( Arduino Esplora + 2 Uno). Basically, when I press the Joystick Button in the Esplora, I'm sending a message to turn on one LED that is attached in one of the Arduinos Uno and also make this Arduino send a message to the other Arduino Uno, asking to print something on the screen.
Can someone help me?
Here is the code of all my 3 devices:
Arduino Esplora:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <Esplora.h>
#include <TFT.h>
RF24 radio(11,3);
int buttonState = 0;
int msgW[1]; // Message that I am going to write
const uint64_t pipeW = 0xE8E8F0F0E1LL; // Channel I am going to use to send the message
void setup()
{
Serial.begin(57600);
EsploraTFT.begin();
radio.begin();
radio.stopListening(); // Stop receiving information
radio.openWritingPipe(pipeW);
}
void loop()
{
int buttonState; //The state of the pin where the toggle switch is
buttonState = Esplora.readJoystickButton();
if(buttonState == HIGH) //Not pressed
{
msgW[0] = 1;
radio.write(msgW, 1);
}
else if(buttonState == LOW) // Pressed
{
msgW[0] = 0;
radio.write(msgW, 1);
}
}
Arduino Uno with the LED:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
const int buttonPin = 7;
RF24 radio(9,10);
int TC;
int msgR[1]; // Vector to save the message received
int msgW[1]; // Vector to save the message I'm going to send
const uint64_t pipeW= 0xE8E8F0F0E2LL; // Pipe I'm going to write to the other UNO
const uint64_t pipeR = 0xE8E8F0F0E1LL; // Pipe I'm going to read from Esplora
void setup()
{
Serial.begin(57600);
pinMode(7,OUTPUT); // LED
radio.begin();
radio.openReadingPipe(1,pipeR);
radio.startListening();
}
void loop()
{
radio.stopListening();
radio.openWritingPipe(pipeW);
TC = 4;
msgW[0] = TC;
radio.write(msgW,1);
//radio.startListening();
if(radio.available())
{
bool done = false;
done = radio.read(msgR,1);
if(msgR[0] == 1) // button not pressed
{
digitalWrite(buttonPin, LOW);
Serial.println(msgR[0]);
}
else if (msgR[0] == 0)
{
digitalWrite(buttonPin,HIGH);
Serial.println(msgR[0]);
}
}
}
Arduino Uno with the LCD:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
const int buttonPin = 7;
RF24 radio(9,10);
int msg[1];
const uint64_t pipeR = 0xE8E8F0F0E2LL; // Pipe I'm going to read to the other UNO
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipeR);
radio.startListening();
}
void loop()
{
if (radio.available())
{
Serial.println("Signal Available");
bool done = false;
done = radio.read(msg,1);
Serial.println(msg[0]);
delay(1000);
}
Serial.println("No Signal!");
delay(1000);
}
Thanks!