Update: I have changed how going about collecting the data, i have setup the code on the nextion editor to send data in a certain format to the arduino:
The code i have for reading this data is this:
// *** Read Data From Screen ***
void Read_LED_Data() {
if(Serial1.available()) {
char character = "";
String data_from_display = "";
delay(30);
while(Serial1.available()) {
character = char(Serial1.read());
data_from_display += character;
}
//Format of Incoming String "A000000" - Letter to determine which Object is sending data & Numbers for value.
//Speed
if(data_from_display.substring(0,1) == "S") { //Check Start of string for Delay Slider Data ("S")
cycleSpeed = data_from_display.substring(2,7).toInt(); //Convert Rest of string to Numerical Value
}
//Colour
if(data_from_display.substring(0,1) == "R") { //Check Start of string for Red Slider Data ("R")
RedValue = data_from_display.substring(2,7).toInt(); //Convert Rest of string to Numerical Value
}
if(data_from_display.substring(0,1) == "G") { //Check Start of string for Green Slider Data ("G")
GreenValue = data_from_display.substring(2,7).toInt(); //Convert Rest of string to Numerical Value
}
if(data_from_display.substring(0,1) == "B") { //Check Start of string for Blue Slider Data ("B")
BlueValue = data_from_display.substring(2,7).toInt(); //Convert Rest of string to Numerical Value
}
//Program
if(data_from_display.substring(0,1) == "P") { //Check Start of string for Pulse Radio Data ("P")
cabinetProg = "Pulse"; //Set Value of cabinetProg to "Pulse"
}
if(data_from_display.substring(0,1) == "D") { //Check Start of string for COn Radio Data ("D")
cabinetProg = "On"; //Set Value of cabinetProg to "On"
}
if(data_from_display.substring(0,1) == "U") { //Check Start of string for DOn Radio Data ("U")
unitProg = "On"; //Set Value of unitProg to "DOn"
}
if(data_from_display.substring(0,1) == "C") { //Check Start of string for Cycle Radio Data ("C")
unitProg = "Cycle"; //Set Value of unitProg to "Cycle"
}
//Test Settings updating in serial monitor
Serial.println("New Settings:-");
Serial.print(" Loop Delay:");
Serial.print(cycleSpeed);
Serial.print(" | RGB Value: ");
Serial.print(" R: ");
Serial.print(RedValue);
Serial.print(" G: ");
Serial.print(GreenValue);
Serial.print(" B: ");
Serial.print(BlueValue);
Serial.print(" | Cabinet Program: ");
Serial.print(cabinetProg);
Serial.print(" | Unit/Display Program: ");
Serial.println(unitProg);
}
when first tested this code it was reading fine but when i added to my loop to apply to my LEDs it stopped reading.
my loop code is:
void loop() {
//*** Read LED Program ***
Read_LED_Data(); // Call Read_LED_Data to check for a change between Loops
// *** Cabinet Program ***
if(cabinetProg == "Pulse"){ //Pulse Loop
// *** Set Cabinet lights to Pulse and white ***
for (int i = 255; i > 0; i--) { // This loop will Gradually Increase the colour value until Highest value
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // This loop will go over each led one at a time
leds[1][i] = CRGB::White;
}
FastLED.show();
delay(10);
}
for (int i = 0; i < 256; i++) { // This loop will Gradually lower the colour value until Lowest value
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // This loop will go over each led one at a time
leds[1][i] = CRGB::Black;
}
FastLED.show();
delay(10);
}
} else { //On
// *** Set Cabinet lights to on and white ***
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // This loop will go over each led one at a time
leds[1][i] = CRGB::White;
FastLED.show();
}
}
// *** Unit/Display Program ***
if(unitProg == "Cycle"){ //Cycle Loop
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // This loop will go over each led one at a time
//*** Read Display Data ***
Read_LED_Data(); // Call Read_LED_Data to check for a change between LEDs
// *** Display LED ***
leds[0][i] = CRGB(RedValue,BlueValue,GreenValue); //Set Selected Colour
FastLED.show();
leds[0][i] = CRGB::Black;
delay(cycleSpeed); // Selected Delay
}
} else { //On
// *** Set Unit lights to on***
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // This loop will go over each led one at a time
leds[0][i] = CRGB(RedValue,BlueValue,GreenValue); //Set Selected Colour
FastLED.show();
}
}
}
i have minimised the library to:
// *** Libraries ***
#include <FastLED.h>
#include <Wire.h>
and my setup to:
// *** Setup LEDs ***
#define NUM_STRIPS 2
#define NUM_LEDS_PER_STRIP 32
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
// *** Startup Speed / Colour / Program ***
int RedValue =0;
int GreenValue =255;
int BlueValue =0;
int cycleSpeed =100;
String cabinetProg = "On";
String unitProg = "Cycle";
void setup() {
//*** Setup Monitor ***
Serial.begin(9600);
Serial1.begin(9600);
// *** Setup LEDs ***
FastLED.addLeds<NEOPIXEL, 2>(leds[0], 32); // No. LEDs on pin 2 (TV Display = 32, Sofa Shelf = 24)
FastLED.addLeds<NEOPIXEL, 4>(leds[1], 18); // No. LEDs on pin 4 (TV Cabinet & Sofa Cabinet = 18)
// *** Set Cabinet lights to on and white ***
for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
leds[1][i] = CRGB::White;
FastLED.show();
}
}