[SOLVED] Arduino Mega and Blynk Slider issue

Hi. I am currently building a fish tank LED light system using an Arduino Mega and Blynk. I have 4 channels of lights (White, Blue, Red and Green for example).

I then have three light modes… lunar, low sun and midsun.

I have separated these light modes using a menu and upon calling each relevant menu, it is SUPPOSED to load each of the channels data to the sliders so that I can adjust if necessary. I then have a save button which will save whatever adjustment I have made.

The problem is, as I move through the different light modes, the previously saved data does not reappear on the slider. For example if I set ch1 on Lunar to 150, if I saved it and then moved to Lowsun menu, and then back to Lunar… I would expect the slider to jump back to 150, but it goes to 0.

Is there a way that I can get it to do this for each of the channels across each of the light modes?

I am very very new to Arduino and Blynk and have limited knowledge of C++ so please be gently.

Here is just a rough copy of code that i have been playing with to learn how to make it work before starting the main sketch.

(Please excuse the messy code, I am just playing about to figure out how to use Blynk)

#define BLYNK_PRINT Serial


#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

char auth[] = "*****HIDDEN*****";

int savechanges;  // used to adjust light levels
int lightedit;    // as above

SoftwareSerial SerialBLE(10, 11); // RX, TX

struct LEDS // for storing light intensity values
{
  float ch1;
  float ch2;
  float ch3;
  float ch4;
};


typedef struct LEDS LightColor;

LightColor lunar = {             // Lunar colours
  0,0,0,0};             
LightColor lowsun = {            // Lowsun colours
  0,0,0,0};              
LightColor midsun = {            // Midsun colours
  0,0,0,0};               
LightColor highsun = {           // Highsun colours
  0,0,0,0};       
LightColor edit = {              // Used to edit colours
  0,0,0,0};

BLYNK_WRITE(V1) 
{
  switch (param.asInt())
  {
    case 1: // Item 1
      lightedit=1;    // 0-NOT EDITING  1-EDIT LUNAR  2-EDIT LOWSUN  3-EDIT MIDSUN
      Serial.println("Lunar Selected");
      Serial.print("lightedit=");
      Serial.println(lightedit);
      edit.ch1=lunar.ch1;
      edit.ch2=lunar.ch2;
      edit.ch3=lunar.ch3;
      edit.ch4=lunar.ch4;
      Blynk.virtualWrite(V2, lunar.ch1);
      Blynk.virtualWrite(V3, lunar.ch2);
      Blynk.virtualWrite(V4, lunar.ch3);
      if (savechanges==1)
      {
        Serial.println("SAVED???");
        lunar.ch1=edit.ch1;
        lunar.ch2=edit.ch2;
        lunar.ch3=edit.ch3;
        lunar.ch4=edit.ch4;
        printall();
      }
      break;
    case 2: // Item 2
      lightedit=2;    // 0-NOT EDITING  1-EDIT LUNAR  2-EDIT LOWSUN  3-EDIT MIDSUN
      Serial.println("Low Sun selected");
      Serial.print("lightedit=");
      Serial.println(lightedit);
      edit.ch1=lowsun.ch1;
      edit.ch2=lowsun.ch2;
      edit.ch3=lowsun.ch3;
      edit.ch4=lowsun.ch4;
      Blynk.virtualWrite(V2, lowsun.ch1);
      Blynk.virtualWrite(V3, lowsun.ch2);
      Blynk.virtualWrite(V4, lowsun.ch3);
      if (savechanges==1)
      {
        Serial.println("SAVED???");
        lowsun.ch1=edit.ch1;
        lowsun.ch2=edit.ch2;
        lowsun.ch3=edit.ch3;
        lowsun.ch4=edit.ch4;
        printall();
      }
      break;
    case 3: // Item 3
      lightedit=3;    // 0-NOT EDITING  1-EDIT LUNAR  2-EDIT LOWSUN  3-EDIT MIDSUN
      Serial.println("Mid Sun selected");
      Serial.print("lightedit=");
      Serial.println(lightedit);
      edit.ch1=midsun.ch1;
      edit.ch2=midsun.ch2;
      edit.ch3=midsun.ch3;
      edit.ch4=midsun.ch4;
      Blynk.virtualWrite(V2, midsun.ch1);
      Blynk.virtualWrite(V3, midsun.ch2);
      Blynk.virtualWrite(V4, midsun.ch3);
      if (savechanges==1)
      {
        Serial.println("SAVED???");
        midsun.ch1=edit.ch1;
        midsun.ch2=edit.ch2;
        midsun.ch3=edit.ch3;
        midsun.ch4=edit.ch4;
        printall();
      }  
      break;
    default:
      Serial.println("Unknown item selected");
  }
}

BLYNK_WRITE(V2)
{
  edit.ch1 = param.asInt(); // assigning incoming value from pin V2 to a variable
  Serial.print("V2 Slider value is: ");
  Serial.println(edit.ch1);
}

BLYNK_WRITE(V3)
{
  edit.ch2 = param.asInt(); // assigning incoming value from pin V2 to a variable
  Serial.print("V3 Slider value is: ");
  Serial.println(edit.ch2);
}

BLYNK_WRITE(V4)
{
  edit.ch3 = param.asInt(); // assigning incoming value from pin V2 to a variable
  Serial.print("V4 Slider value is: ");
  Serial.println(edit.ch3);
}

BLYNK_WRITE(V10)
{
  int savechanges = param.asInt(); // assigning incoming value from pin V10 to a variable
  savevalues();
}

BLYNK_WRITE(V11)
{
  int printa = param.asInt();
  if (printa==1)
  {
    printall();
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");
}

void savevalues()
{
  if (lightedit==1)    // 0-NOT EDITING  1-EDIT LUNAR  2-EDIT LOWSUN  3-EDIT MIDSUN
  {
    lunar.ch1=edit.ch1;
    lunar.ch2=edit.ch2;
    lunar.ch3=edit.ch3;
    lunar.ch4=edit.ch4;
    Serial.println("SAVE VALUES 1");
    printall();
  }
  else if (lightedit==2)
  {
    lowsun.ch1=edit.ch1;
    lowsun.ch2=edit.ch2;
    lowsun.ch3=edit.ch3;
    lowsun.ch4=edit.ch4;
    Serial.println("SAVE VALUES 2");
    printall();
  }
  else if (lightedit==3)
  {
    midsun.ch1=edit.ch1;
    midsun.ch2=edit.ch2;
    midsun.ch3=edit.ch3;
    midsun.ch4=edit.ch4;
    Serial.println("SAVE VALUES 3");
    printall();
  }
}

        

void printall()
{
  Serial.println("=============================================");
  Serial.print("LUNAR EDIT: ");Serial.print(edit.ch1);Serial.print(" - ");Serial.print(edit.ch2);Serial.print(" - ");Serial.println(edit.ch3);
  Serial.print("LUNAR REAL: ");Serial.print(lunar.ch1);Serial.print(" - ");Serial.print(lunar.ch2);Serial.print(" - ");Serial.println(lunar.ch3);
  Serial.println("=============================================");
  Serial.print("LOWSUN EDIT: ");Serial.print(edit.ch1);Serial.print(" - ");Serial.print(edit.ch2);Serial.print(" - ");Serial.println(edit.ch3);
  Serial.print("LOWSUN REAL: ");Serial.print(lowsun.ch1);Serial.print(" - ");Serial.print(lowsun.ch2);Serial.print(" - ");Serial.println(lowsun.ch3);
  Serial.println("=============================================");
  Serial.print("MIDSUN EDIT: ");Serial.print(edit.ch1);Serial.print(" - ");Serial.print(edit.ch2);Serial.print(" - ");Serial.println(edit.ch3);
  Serial.print("MIDSUN REAL: ");Serial.print(midsun.ch1);Serial.print(" - ");Serial.print(midsun.ch2);Serial.print(" - ");Serial.println(midsun.ch3);
  Serial.println("=============================================");
}


void loop()
{
  Blynk.run();
}

The problem is, as I move through the different light modes, the previously saved data does not reappear on the slider.

Can you post a picture of the slider attached to the Arduino? Can you post some details about how you exptect data to appear on this slider?

The slider is a digital slider on the Blynk software which is on a Samsung tablet connected to the arduino via bluetooth. There is no actual physical sliders.

Its ok, sorted. Someone from the Blynk forums come up with the answer. Its because the sliders on Blynk don’t work with floats. I changed them to integers and worked first time!!