//Receiving side arduino UNO
#include <FastLED.h>
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 15
#define BRIGHTNESS 96
CRGB leds[NUM_LEDS];
#include <Wire.h> // For I2C
#include <LCD.h> // For LCD
#include <LiquidCrystal_I2C.h> // Added library*
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default I2C bus address of the backpack-see article
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte addresses [][6] = {"00001", "00002"}; //Setting the two addresses. One for transmitting and one for receiving
int confirmLEDright = 2; //led pin for debugging
int spk = 8; //speaker pin
int Ledstateone;
int Ledstatetwo;
int Ledstatethree;
int Ledstatefour;
int Ledstatefive;
int Ledstatesix;
int Ledstateseven;
int Ledstateeight;
int VAL; //value that is read from potentiometer and used for delay
int Ledstates[9]={Ledstateone, Ledstatetwo, Ledstatethree, Ledstatefour, Ledstatefive, Ledstatesix, Ledstateseven, Ledstateeight, VAL};
void setup() {
Serial.begin(9600);
lcd.begin (20,4); // 20 x 4 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH); //If the text is dim, check this line
radio.begin(); //Starting the radio communication
radio.openWritingPipe(addresses[1]); //Setting the address at which we will send the data
radio.openReadingPipe(1, addresses[0]); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening();
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // initializes LED strip
FastLED.setBrightness(BRIGHTNESS);// global brightness
pinMode(spk, OUTPUT);
pinMode(confirmLEDright, OUTPUT);
digitalWrite(confirmLEDright, HIGH);
delay(300);
digitalWrite(confirmLEDright, LOW);
tone(spk, 500);
delay(100);
noTone(spk);
tone(spk, 700);
delay(100);
noTone(spk);
tone(spk, 1000);
delay(100);
noTone(spk);
}
// switches off all LEDs
void showProgramCleanUp(long delayTime) {
for (int i = 0; i < NUM_LEDS; ++i) {
leds[i] = CRGB::Black;
}
FastLED.show();
radio.read(&Ledstates, sizeof(Ledstates)); //Reads the potentiometer value
Serial.print(VAL);
Serial.print("_");
delay(VAL);
}
// Shifts a single pixel from the start of strip to the end.
// crgb: color of shifted pixel
// delayTime: indicates how long the pixel is shown on each LED
void showProgramShiftSinglePixel(CRGB crgb, long delayTime) {
for (int i = 0; i < NUM_LEDS; ++i) {
leds[i] = crgb;
FastLED.show();
radio.read(&Ledstates, sizeof(Ledstates)); //Reads the potentiometer value
Serial.print(VAL);
Serial.print("_");
delay(VAL);
leds[i] = CRGB::Black;
}
}
// Shifts multiple pixel from the start of strip to the end. The color of each pixel is randomized.
// delayTime: indicates how long the pixels are shown on each LED
void showProgramShiftMultiPixel(long delayTime) {
for (int i = 0; i < NUM_LEDS; ++i) {
for (int j = i; j > 0; --j) {
leds[j] = leds[j-1];
}
CRGB newPixel = CHSV(random8(), 255, 255);
leds[0] = newPixel;
FastLED.show();
radio.read(&Ledstates, sizeof(Ledstates)); //Reads the potentiometer value
delay(VAL);
leds[i] = CRGB::Black;
}
}
void loop()
{
//////////////////////////////////////////////////////////////////////////////////////////////1st color//////////
radio.startListening(); //This sets the module as receiver
radio.read(&Ledstates, sizeof(Ledstates)); //Reads the ledstateone value
if (Ledstates[0] == HIGH) //If ledstateone is HIGH then show GREEN color
{
Serial.print(Ledstates[0]);
Serial.print("show GREEN ");
showProgramShiftSinglePixel(CRGB::Lime, 100); //Shows the GREEN colour
}
radio.read(&Ledstates, sizeof(Ledstates));
if (Ledstates[0] == LOW) //If ledstatetwo is LOW then turn off leds
{
Serial.print(Ledstates[0]);
Serial.print("turn off Ledstateone ");
showProgramCleanUp(2500); // clean up, turns off leds
}
///////////////////////////////////////////////////////////////////////////////////////////2nd color////////////////
radio.startListening(); //This sets the module as receiver
radio.read(&Ledstates, sizeof(Ledstates)); //Reads the ledstatetwo value
if (Ledstates[1] == HIGH) //If ledstatetwo is HIGH then show RED color
{
Serial.print(Ledstates[1]);
Serial.print("show RED ");
showProgramShiftSinglePixel(CRGB::Maroon, 250); //Shows the RED colour
}
radio.read(&Ledstates, sizeof(Ledstates));
if (Ledstates[1] == LOW) //If ledstatetwo is LOW then turn off leds
{
Serial.print(Ledstates[1]);
Serial.print("turn off Ledstatetwo ");
showProgramCleanUp(2500); // clean up, turns off leds
}
}