Global variable value not getting updated if another global variable value is increased

I am having a problem with the code below running on UNO.

As you can see there is a global int String data_config;and another global int WIDTH=5;

The function EEPROMread() which is being called by void setup() is actually reading characters from EEPROM and creating a character array variable "data" having last character as null ,this can be treated as a string value which is being updated to the variable data_config.

The program works well until the value of variable WIDTH is greater than 5
When WIDTH is greater than 5 the value of variable data is being generated but the value of data_config doesn't changes despite of storing the value

#include <SPI.h>
#include <DMD.h>
//#include <DMD2.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include <EEPROM.h>

#define FONT Arial_Black_16

//char c[100];
char WIDTH1 =EEPROM.read(136);
char HEIGHT2 =EEPROM.read(139);
int WIDTH=5;/*WIDTH1-'0';*/
int HEIGHT=2;/*HEIGHT1-'0';*/
int number_of_lines=1;
int b1=40;
int b2=40;
int b3=40;
int b4=40;
int b5=40;
int b6=40;
int b7=40;
int b8=40;
int b9=40;
int b10=40;

String a1="F";
String a2="F";
String a3="F";
String a4="F";
String a5="F";
String a6="F";
String a7="F";
String a8="F";
String a9="F";
String a10="F";

String l1="";
String l2="";
String l3="";
String l4="";
String l5="";
String l6="";
String l7="";
String l8="";
String l9="";
String l10="";

String s1="TEXT 1";
String s2="TEXT 2";
String s3="YYYY";
String s4="";
String s5="";
String s6="";
String s7="";
String s8="";
String s9="";
String s10="";


String s="";
int movement_speed=50;
int i=1;
uint8_t EEPROMadress =136;
String data_config;
String EEPROMdataRead="v";
String incomming_data="1";


DMD led_module(WIDTH, HEIGHT);

//SoftDMD dmd(WIDTH,HEIGHT);
//DMD_TextBox box(dmd, 0, 0,(DISPLAY_WIDE*16) ,(DISPLAY_HIGH*16));


void scan_module()
{
  
  led_module.scanDisplayBySPI();
  
}


void EEPROMwrite()
{
  int _size = data_config.length();
  
  int i;
  for(i=0;i<_size;i++)
  {
    EEPROM.write(EEPROMadress+i,data_config[i]);
  }
  EEPROM.write(EEPROMadress+_size,'\0');   //Add termination null character for String Data
  EEPROMadress =136;
}
void EEPROMread()
{
  int i;
  char data[100]; //Max 100 Bytes
  int len=0;
  unsigned char k;
  k=EEPROM.read(EEPROMadress);
  while(k != '\0' && len<500)   //Read until null character
  {    
    k=EEPROM.read(EEPROMadress+len);
    data[len]=k;
    //c[len]=k;
    Serial.println(data[len]);
    len++;
    
  }
  Serial.println(len);
  data[len]="\0";
  //c[len]="\0";
  Serial.println(data);
  EEPROMdataRead=data;
  //String axyz=String(data);
   //delay(1000);
  //Serial.println(axyz);
 Serial.println(EEPROMdataRead.length());
 
  data_config=EEPROMdataRead;
  //data_config=data;
  Serial.println(data_config);
  //data_augmentation();
  //return(data);
}
void data_augmentation()
{
int  WIDTH1=data_config[data_config.indexOf("w")-1]-'0';
int  HEIGHT1=data_config[data_config.indexOf("h")-1]-'0';
  /*if(WIDTH!=WIDTH)
  EEPROM.write(230,WIDTH);
  if(HEIGHT1!=HEIGHT)
  EEPROM.write(231,HEIGHT);*/
  number_of_lines=(data_config[(data_config.indexOf("n")-1)])-'0';//- 0 to conver chat to int
  
  switch(number_of_lines)
  {
    case 1:
   //Serial.print(number_of_lines);
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    break;

    case 2:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    break;

    case 3:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    break;

    case 4:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    break;

    case 5:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    break;

    case 6:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    b6=(data_config[(data_config.indexOf("b6")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    a6=data_config[(data_config.indexOf("a6")-1)];
    break;

    case 7:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    b6=(data_config[(data_config.indexOf("b6")-1)])-'0';
    b7=(data_config[(data_config.indexOf("b7")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    a6=data_config[(data_config.indexOf("a6")-1)];
    a7=data_config[(data_config.indexOf("a7")-1)];
    break;

    case 8:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    b6=(data_config[(data_config.indexOf("b6")-1)])-'0';
    b7=(data_config[(data_config.indexOf("b7")-1)])-'0';
    b8=(data_config[(data_config.indexOf("b8")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    a6=data_config[(data_config.indexOf("a6")-1)];
    a7=data_config[(data_config.indexOf("a7")-1)];
    a8=data_config[(data_config.indexOf("a8")-1)];
    break;

    case 9:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    b6=(data_config[(data_config.indexOf("b6")-1)])-'0';
    b7=(data_config[(data_config.indexOf("b7")-1)])-'0';
    b8=(data_config[(data_config.indexOf("b8")-1)])-'0';
    b9=(data_config[(data_config.indexOf("b9")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    a6=data_config[(data_config.indexOf("a6")-1)];
    a7=data_config[(data_config.indexOf("a7")-1)];
    a8=data_config[(data_config.indexOf("a8")-1)];
    a9=data_config[(data_config.indexOf("a9")-1)];
    break;

    case 10:
    b1=(data_config[(data_config.indexOf("b1")-1)])-'0';
    b2=(data_config[(data_config.indexOf("b2")-1)])-'0';
    b3=(data_config[(data_config.indexOf("b3")-1)])-'0';
    b4=(data_config[(data_config.indexOf("b4")-1)])-'0';
    b5=(data_config[(data_config.indexOf("b5")-1)])-'0';
    b6=(data_config[(data_config.indexOf("b6")-1)])-'0';
    b7=(data_config[(data_config.indexOf("b7")-1)])-'0';
    b8=(data_config[(data_config.indexOf("b8")-1)])-'0';
    b9=(data_config[(data_config.indexOf("b9")-1)])-'0';
    b10=(data_config[(data_config.indexOf("b10")-1)])-'0';
    a1=data_config[(data_config.indexOf("a1")-1)];
    a2=data_config[(data_config.indexOf("a2")-1)];
    a3=data_config[(data_config.indexOf("a3")-1)];
    a4=data_config[(data_config.indexOf("a4")-1)];
    a5=data_config[(data_config.indexOf("a5")-1)];
    a6=data_config[(data_config.indexOf("a6")-1)];
    a7=data_config[(data_config.indexOf("a7")-1)];
    a8=data_config[(data_config.indexOf("a8")-1)];
    a9=data_config[(data_config.indexOf("a9")-1)];
    a10=data_config[(data_config.indexOf("a10")-1)];
    break;

  
    
    
    
  }
  Serial.println("data augmentaton check");  
  
}
void scrolling()
{
   
    if(a1=="S"){
    //Serial.print(a1);
    //led_module.setBrightness(20);
    led_module.drawMarquee(s1.c_str() ,s1.length(), (32 * WIDTH),8);
    
    long start = millis();
    long timming = start;
    boolean flag = false;
    while (!flag)
    {
      if ((timming +movement_speed) < millis()) 
      {
        flag = led_module.stepMarquee(-1, 0);
        timming = millis();
      }
    }
   
    }
}
void fixed()
{
  led_module.drawString( 0,0, s1.c_str(), s1.length(), GRAPHICS_NORMAL );
}

void check()
{
  Serial.print("check");
  if(a1=="S")
  scrolling();
  else if(a1=="F")
  fixed();
}







void setup()
{
  
  Serial.begin(9600);
  delay(100);
  Serial.println("test");
  EEPROMread();
  //Serial.println(EEPROMread());
  //Serial.println(data_config);
  Timer1.initialize(2000);
  Timer1.attachInterrupt(scan_module);
  led_module.clearScreen( true );
  
  
  led_module.selectFont(FONT);

   delay(1000);
  
 
  
}

void loop()
{
    
    
    
    //while(incomming_data=="1"){
    if(Serial.available() > 0)  
    {
      incomming_data=String(Serial.readString());
      
    }
    Serial.println(incomming_data);
    delay(10);
   // }
   
    int len=incomming_data.length();
    if(incomming_data.indexOf("#")!=-1)
    {
      data_config=incomming_data;
      Serial.println("#detcted");
      EEPROMwrite();
      delay(200);
      EEPROMread();
      delay(200);
      data_augmentation();
    }
    else if(i==1||incomming_data!="1")
    {
      Serial.println("i1");
      data_augmentation();
    }
    else
    check();
    i++;
    delay(100);
    incomming_data="1";
}





post your code in code tags.

code and output properly posted

Hello
Well I think you shall do some research for the use of Strings inside the Arduino biotop.

Are you having trouble because updating the local 'int' variables 'WIDTH1' and 'HEIGHT1' don't update the global 'int' variables 'WIDTH' or 'HEIGHT' or the global 'char' variables 'WIDTH1' or 'HEIGHT2'?

1 Like