how to assign an array to this...

ok so i got help on another thread about an issue i was having with space... they advice me on this

Now the variables (such as mistingTXOnH, mistingTXOnM, mistingTXOnS, mistingTXOffH, mistingTXOffM, mistingTXOffS, mistingSwitchXOnOff ) can all be arrays. Within your function you can then get the value of any of them just given the value of X

how would i make an array for
mistingTxOnH
mistingTxOnM
mistingTxOnS

mistingTxOffH
mistingTxOffM
mistingTxOffS

i tryed
byte mistingT[]OnH, mistingT[]OnM, mistingT[]OnS,
mistingT[]OffH, mistingT[]OffM, mistingT[]OffS;

but its not working?

i wanted x to be in a "for" function:

for (x=1; x<5; x++)
        {
          myGLCD.drawRect(0, (28 + x * 28) , 319, (28 + x * 28)); //Horizontal Divider for 1-4
          
          if ((mistingT[x]OnH==0) && (mistingT[x]OnM==0) && (mistingT[x]OnS==0) 
               && (mistingT[x]OffH==0) && (mistingT[x]OffM==0) && (mistingT[x]OffS==0)){
                 myGLCD.setColor(0, 0, 0);
                 myGLCD.fillRect(1, (4 + x * 28), 318, (27 + x * 28));          //Clears on/off timer if Reset or timer is on 0.
                 setFont(SMALL, 255, 0, 0, 0, 0, 0);
                 myGLCD.print("Timer " x " has not been Scheduled.", CENTER, (10 + x * 28));

any help on doing it the right way? i'm not sure how to make an array for this...

the advice that i got didnt make sense to me... still new at arduino coding so noob alert here...

This sketch results 4 sets of 5 pulses.
I change the values of the members of myMatrix "on the fly" as I guess you're angling at.

byte myMatrix[2];

void setup ()
{
  pinMode(13,OUTPUT);
}

void loop ()
{
  myMatrix[0] = 10;
  myMatrix[1] = 75;
  blinking();
  delay(2000);
  myMatrix[0] = 100;
  myMatrix[1] = 250;
  blinking();
  delay(2000);
}

void blinking ()
{
  for(byte t=0; t<5; t++)
  {
    digitalWrite(13,HIGH);
    delay (myMatrix[0]);
    digitalWrite(13,LOW);
    delay(500 - myMatrix[0]);
  }
  delay(1000);
  for(byte t=0; t<5; t++)
  {
    digitalWrite(13,HIGH);
    delay(myMatrix[1]);
    digitalWrite(13,LOW);
    delay(500 - myMatrix[1]);
  }
}

i am confused... i have no idea what i am looking at... or how it would do what i am asking above...

Just trying to show you how to place values into an array and use them.
I wasn't trying to absolutely solve your conundrum.

Did you run the sketch or is that a bridge too far?

oh no i didnt need to place a value on the variable...

for example...

i have 4 different sets of byte variables label from 1-4

mistingT1OnH - byte variable
mistingT1OnM - byte variable
mistingT1OnS - byte variable
mistingT1OffH - byte variable
mistingT1OffM - byte variable
mistingT1OffS - byte variable

mistingT2OnH - byte variable
mistingT2OnM - byte variable
mistingT2OnS - byte variable
mistingT2OffH - byte variable
mistingT2OffM - byte variable
mistingT2OffS - byte variable

mistingT3OnH - byte variable
mistingT3OnM - byte variable
mistingT3OnS - byte variable
mistingT3OffH - byte variable
mistingT3OffM - byte variable
mistingT3OffS - byte variable

mistingT4OnH - byte variable
mistingT4OnM - byte variable
mistingT4OnS - byte variable
mistingT4OffH - byte variable
mistingT4OffM - byte variable
mistingT4OffS - byte variable

as you can see there is 4 of the same byte variables name but each one has a name of 1-4

is there a way to make the variable name number to x and then have x read from 1-4 like in a "for" loop?

or does these byte variable name cant be done?

You could probably do something like this

byte nH = 0
byte nM = 1
byte nS = 2
byte ffH = 3
byte ffM = 4
byte ffS = 5

byte mistingT[4][6]; // a 2-dimensional array

// and then in your code use it like this

mistingT[0][nH] = xxx;

Is there enough in that to give you the idea?

Note the the first array is indexed from 0 to 3, and not 1 to 4

...R

I prefer using an array of objects for this kind of thing. Alot easier and possibly safer to work with. Although an array has the advantage of accessing the second dimension sequentially, it may not be a useful feature in this app if each element is explicitly accessed anyway.

struct MistingData{
  byte nH;
  byte nM;
  byte nS;
  byte ffH;
  byte ffM;
  byte ffS;
};
 
MistingData mistingT[4]; 

//... 
mistingT[0].nH = xxx;

pYro_65:
I prefer using an array of objects for this kind of thing.

That looks a lot neater - unless you also need to be able to iterate over the nH, nM, nS etc parts.

...R

Robin2:
That looks a lot neater - unless you also need to be able to iterate over the nH, nM, nS etc parts.

...R

I mentioned that, however classes allow you to provide both methods. Each element is the same size so this is easy. Want to see how?

With a simple overload of the subscript operator, your iteration needs are fulfilled!

struct MistingData{
  byte nH;
  byte nM;
  byte nS;
  byte ffH;
  byte ffM;
  byte ffS;
  byte &operator []( int idx ){ return *( (byte*)this + idx ); }
};

MistingData mistingT[4];

//Now you can access the data explicitly, or in an iteration. 
//The statements below do the same thing:

void setup(){
  mistingT[0].nS = 1;
  mistingT[0][2] = 1;
}

By adding a conversion operator which converts the class into a 'reference to an array' we can also use C++11 ranged loop to iterate it ( not just standard loops ):

struct MistingData{
  byte nH;
  byte nM;
  byte nS;
  byte ffH;
  byte ffM;
  byte ffS;
  byte &operator []( int idx ){ return *( (byte*)this + idx ); }
  
  typedef byte arr_t[6];
  &operator arr_t(){ return *( ( arr_t* ) this ); }
};
  
MistingData mistingT[4];


void setup() {

  mistingT[0].nS = 1;
  mistingT[0][2] = 1;
  
  for( auto i : mistingT ){
    for( auto j : i ){
      //Use j
    } 
  }
}

void loop() {}

Before you argue, hey I don't use C++11, you can recreate that loop easily for C++98 ( it uses pointers ).

But hey C++11 is great (enable it in 1.5.7 and above), because you may also argue, "I do not like the overloads, they look confusing". Well we can use the mechanism developed in C++98 for iteration ( which gave birth to the C++11 ranged loop ).

We can strip all the overloads out, and add in the 'free' functions begin() and end(). These return iterators to the start and end of the data, in our case: pointers.

Without the operators you cannot access it like an array, however you can iterate it:

struct MistingData{
  byte nH;
  byte nM;
  byte nS;
  byte ffH;
  byte ffM;
  byte ffS;
  
  byte *begin(){ return &nH; }
  byte *end(){ return &ffS; }
};
  
MistingData mistingT[4];


void setup() {

  for( auto i : mistingT ){
    for( auto j : i ){
      //Use j
    } 
  }
}

void loop() {}

Simple huh.

The C++98 version is easy to find, however its better to try and work it out. ( a for using pointers, not an index ).

Whats the advantage over the array you ask?

Well its a class, it can have functions, static members, inherited functionality, the list goes on...

Cheers,
Chris

pYro_65:
With a simple overload of the subscript operator, your iteration needs are fulfilled!

byte &operator []( int idx ){ return ( (byte)this + idx ); }

It may be simple in the sense of not needing much typing.

But it is far from simple to understand - but then I avoid C/C++ as much as I can.

...R

this is what i am doing.....

void displayTimerScreen()
{
     if (offMisting2RH>0)
       {
         setFont(LARGE, 0, 255, 0, 0, 0, 0);
         myGLCD.print("On", 207, 145);
       } else {
         setFont(LARGE, 255, 0, 0, 0, 0, 0);
         myGLCD.print("Off", 207, 145);}
         
     setFont(LARGE, 255, 255, 255, 0, 0, 0);
     myGLCD.print("Set 2 RH%:", 45, 145);
     setFont(SMALL, 255, 0, 0, 0, 0, 0);
     myGLCD.print("If Misting is set on RH%, all Set", CENTER, 166);
     myGLCD.print("Misting Timer will be disabled.", CENTER, 181);
     
     printHeader("Set Misting Timer");
     
     setFont(SMALL, 0, 255, 255, 0, 0, 0);
     myGLCD.print("ON", 53, 19);
     myGLCD.print("OFF", 100, 19);
     myGLCD.print("Days", 186,19);
     myGLCD.setColor(56, 142, 142);
     myGLCD.drawRect(0, 29, 319, 31);              //Horizontal Divider Timer/on/off
   
   byte timerOnH[]={0, mistingT1OnH, mistingT2OnH, mistingT3OnH, mistingT4OnH};
   byte timerOnM[]={0, mistingT1OnM, mistingT2OnM, mistingT3OnM, mistingT4OnM}; 
   byte timerOnS[]={0, mistingT1OnS, mistingT2OnS, mistingT3OnS, mistingT4OnS};
   byte timerOffH[]={0, mistingT1OffH, mistingT2OffH, mistingT3OffH, mistingT4OffH};
   byte timerOffM[]={0, mistingT1OffM, mistingT2OffM, mistingT3OffM, mistingT4OffM};
   byte timerOffS[]={0, mistingT1OffS, mistingT2OffS, mistingT3OffS, mistingT4OffS};
   byte timerAmPmOnx[]={0, timerAmPm1On, timerAmPm2On, timerAmPm3On, timerAmPm4On};
   byte timerAmPmOffx[]={0, timerAmPm1Off, timerAmPm2Off, timerAmPm3Off, timerAmPm4Off};
   byte timerSetSux[]={0, timerSetSu1, timerSetSu2, timerSetSu3, timerSetSu4},
        timerSetMox[]={0, timerSetMo1, timerSetMo2, timerSetMo3, timerSetMo4},
        timerSetTux[]={0, timerSetTu1, timerSetTu2, timerSetTu3, timerSetTu4},
        timerSetWex[]={0, timerSetWe1, timerSetWe2, timerSetWe3, timerSetWe4},
        timerSetThx[]={0, timerSetTh1, timerSetTh2, timerSetTh3, timerSetTh4},
        timerSetFrx[]={0, timerSetFr1, timerSetFr2, timerSetFr3, timerSetFr4},
        timerSetSax[]={0, timerSetSa1, timerSetSa2, timerSetSa3, timerSetSa4};
   byte mistingSwitchOnOff[]={0, mistingSwitch1OnOff, mistingSwitch2OnOff, mistingSwitch3OnOff, mistingSwitch4OnOff};
   
     for (x=1; x<5; x++)
        {
          myGLCD.setColor(56, 142, 142);
          myGLCD.drawRect(0, (28 + x * 28) , 319, (28 + x * 28)); //Horizontal Divider for 1-4
          
          if ((timerOnH[x]==0) && (timerOnM[x]==0) && (timerOnS[x]==0) 
               && (timerOffH[x]==0) && (timerOffM[x]==0) && (timerOffS[x]==0)){
                 myGLCD.setColor(0, 0, 0);
                 myGLCD.fillRect(1, (4 + x * 28), 318, (27 + x * 28));          //Clears on/off timer if Reset or timer is on 0.
                 setFont(SMALL, 255, 0, 0, 0, 0, 0);
                 myGLCD.print("Timer 1 has not been Scheduled.", CENTER, (10 + x * 28));
                 myGLCD.printNumI(x, 83, (10 + x * 28));
          } else {
              if (mistingSwitchOnOff[x]==0){                //If Timer is off displays red background
                      myGLCD.setColor(255, 0, 0);
                      myGLCD.fillRect(1, (4 + x * 28), 318, (27 + x * 28));
                      setFont(SMALL, 255, 255, 255, 255, 0, 0);
              } else {
                      myGLCD.setColor(0, 255, 0);          //If Timer is on, Displays green background
                      myGLCD.fillRect(1, (4 + x * 28), 318, (27 + x * 28));
                      setFont(SMALL, 0, 0, 0, 0, 255, 0);}
                      
                     
              if (timerOnH[x]<10)
                { myGLCD.printNumI(0, 33, (4 + x * 28));
                  myGLCD.printNumI(timerOnH[x], 41, (4 + x * 28));}
              else
                { myGLCD.printNumI(timerOnH[x], 33, (4 + x * 28));}
              myGLCD.print(":", 47, (4 + x * 28));
             if (timerOnM[x]<10)
                { myGLCD.printNumI(0, 53, (4 + x * 28));
                  myGLCD.printNumI(timerOnM[x], 61, (4 + x * 28));}
              else
                { myGLCD.printNumI(timerOnM[x], 53, (4 + x * 28));}
              myGLCD.print(":", 67, (4 + x * 28));
             if (timerOnS[x]<10)
                { myGLCD.printNumI(0, 73, (4 + x * 28));
                  myGLCD.printNumI(timerOnS[x], 81, (4 + x * 28));}
              else
                { myGLCD.printNumI(timerOnS[x], 73, (4 + x * 28));}
                
                
             if (timerOffH[x]<10)
                { myGLCD.printNumI(0, 83, (15 + x * 28));
                  myGLCD.printNumI(timerOffH[x], 91, (15 + x * 28));}
              else
                { myGLCD.printNumI(timerOffH[x], 83, (15 + x * 28));}
              myGLCD.print(":", 97, (15 + x * 28));
             if (timerOffM[x]<10)
                { myGLCD.printNumI(0, 103, (15 + x * 28));
                  myGLCD.printNumI(timerOffM[x], 111, (15 + x * 28));}
              else
                { myGLCD.printNumI(timerOffM[x], 103, (15 + x * 28));}
              myGLCD.print(":", 117, (15 + x * 28));
             if (timerOffS[x]<10)
                { myGLCD.printNumI(0, 123, (15 + x * 28));
                  myGLCD.printNumI(timerOffS[x], 131, (15 + x * 28));}
              else
                { myGLCD.printNumI(timerOffS[x], 123, (15 + x * 28));}
                
                
                
             if (setTimeFormat==1)                            //Is time set on 12hours
                {
                 if (timerAmPmOnx[x]==1){
                       myGLCD.print("AM", 92, (4 + x * 28));
                 } else {
                       myGLCD.print("PM", 92, (4 + x * 28));}
                       
                 if (timerAmPmOffx[x]==1){
                       myGLCD.print("AM", 142, (15 + x * 28));
                 } else {
                       myGLCD.print("PM", 142, (15 + x * 28));}
                }
                
              myGLCD.printNumI(x, 10, (10 + x * 28));
              myGLCD.print(":", 18, (10 + x * 28));
              if (timerSetSux[x]==7){
                    myGLCD.print("Su", 164, (4 + x * 28));}
              if (timerSetMox[x]==1){
                    myGLCD.print("Mo", 184, (4 + x * 28));}
              if (timerSetTux[x]==2){
                    myGLCD.print("Tu", 204, (4 + x * 28));}
              if (timerSetWex[x]==3){
                    myGLCD.print("We", 224, (4 + x * 28));}
              if (timerSetThx[x]==4){
                    myGLCD.print("Th", 174, (15 + x * 28));}
              if (timerSetFrx[x]==5){
                    myGLCD.print("Fr", 194, (15 + x * 28));}
              if (timerSetSax[x]==6){
                    myGLCD.print("Sa", 214, (15 + x * 28));}
              if (mistingSwitchOnOff[x]==0){                //If Timer is off displays red background
                   printButton("On", onOffTimerButton1[0], (5 + x * 28), onOffTimerButton1[2], (25 + x * 28), SMALL);   //Timer off
              } else {
                   printButton("Off", onOffTimerButton1[0], (5 + x * 28), onOffTimerButton1[2], (25 + x * 28), SMALL);}   //Timer on
                   printButton("Reset", resetTimerButton1[0], (5 + x * 28), resetTimerButton1[2], (25 + x * 28), SMALL); //Timer Reset  
            }
        }
        
     myGLCD.setColor(56, 142, 142);                    //Draw Dividers in Grey
     myGLCD.drawRect(0, 196, 319, 194);              //Bottom Horizontal Divider
     printButton("<< BACK", back[0], back[1], back[2], back[3], SMALL);
     printButton("Set 2 RH%", prSAVE[0], prSAVE[1], prSAVE[2], prSAVE[3], SMALL);
     printButton("CANCEL", canC[0], canC[1], canC[2], canC[3], SMALL);
}

is there any way to make this code more compact so it uses less space?

if you can edit this function above it would be great thanks...

Robin2:
But it is far from simple to understand - but then I avoid C/C++ as much as I can.

Hmmm, you've used that excuse a few times now. Can tell you are an oldie...

Really its a simple C++ concept... Its a function, all the additions are functions. A quick read of a reference and you'll be set.

pYro_65:
Hmmm, you've used that excuse a few times now. Can tell you are an oldie...

62.5 Much prefer Python or Ruby

More seriously, my comment was intended to raise the question of whether a newcomer would understand your approach.

...R

More seriously, my comment was intended to raise the question of whether a newcomer would understand your approach.

I wrote it with the assumption that it would be new to many people.

Regardless of whether a particular person understands it, the people who are curios enough to investigate some of the keywords throughout my post will be able to learn a new approach. Reading separate C++ manuals on overloading and data structures will inform you how to use the feature, but mixing concepts into clever solutions typically comes from experience and usually involve some complexities whether it be something like my example above, or converting a simple math routine into highly efficient bit manipulation using a few shifts and such. I have not been taught to program, my knowledge is mostly from researching and using interesting code I have found, which I may not have understood at first.