how to make a Progress Bar in 2.4" LCD and Mega2560

hi everybody !

i have a question for make a graphical (green-red) progress bar, that which shows a value from an 2-D array ?

i upload an images from my process !

i have 3 screens in screen=1 user must be select an Ah. for battery with "left" & "right" touch buttons and this value showed in this screen (ie. 000 Ah.)
we have 15 capacity(Ah) for battery that can be viewed and selected in "screen=1"
and after press "set" buttons the related time(in sec.) for capacity(Ah.) must be showed in the progress bar at next screen (ie. screen=4) and the progress bar count-down to zero with 1sec. steps and after that print the voltage and battery test result

the full loaded progress bar must be green and below the 10sec. must be changed to red

i write 4 functions for this:
set_func() that shows the screen=4 contents and progress bar and result
r_func() that for selecting next Ah. ---> it calles after .justPressed happened (in screen=1)
l_func() for selecting lower values.(previous Ah.). ---> it calles after .justPressed happened(in screen=1)
batt_func() for screen=1 contents and select and show Ah.

===> but i dont have an idea how to do this ? ?
1- using swith() case: for selecting ?
2- or using 2-D array and work with indexing
3- or make two 1-D array (maybe its easier)

can anyone send me a sample code for this ? or sample code for making a progress bar?

thanks !

  1. You should be able to draw each screen with its buttons.

  2. You should be able to perform some action according to buttons.

  3. e.g. print message, update number field, jump between screens according to buttons.

  4. you can draw a progress bar. look at GFX graphics methods. e.g. drawRect(), fillRect(), ...

I am sure that you can design your own program.

David.

ok !

i want to move and select between 2-d arrays elements but not working ?
i dont know my definition is true? (=my 2-d array)

//2-D array for selecting battery Ah. and time:
int i, j; //for index of array
const uint8_t cap_list[15][2] = 
{
  12,2,
  18,3,
  35,4,
  50,5,
  55,6,
  62,8,
  66,10,
  74,12,
  88,14,
  100,15,
  120,16,
  150,18,
  170,20,
  200,22,
  220,25
};

void batt_func(){
  tft.setCursor(90,150);
  tft.print(cap_list [ i ] [ 0 ] ); //show Ah. on LCD
  tft.setCursor(140,150);
  tft.println("Ah.");

}

//r_func() ---> higher Ah.:
void r_func(){  
  for(i,j; 0 <= i <= 13 & j < 1; i++,j++){
    //for(j; ; j++){
      cap_list [ i ] [ j ] ;
    //}
  }
  
}

//l_func() ---> lower Ah.:
void l_func(){
  for(i,j; 0 < i <= 14 & j > 1; i--,j--){
    //for(j; j > 1; j--){
      cap_list [ i ] [ j ] ;
    //}
  }

Please use a Code Window when pasting code. You are not a "new" member. Read the Forum instructions on how to use the </> icon.

Members will simply ignore your posts if you ignore the Forum etiquette.

David.

ok!

i make the list of Ah. in two arrays, but when i moving between the array elements there show something greater and lower than my elements value ---> how can i bound the moving to my elements only?

and my if() statements cant deny showing this undesired values ?

my code is:

uint8_t i, j;
const uint8_t ah_list[15] = {12, 18, 35, 50, 55, 62, 66, 74, 88, 100, 120, 150, 170, 200, 220};
const uint8_t time_list[15] = {2, 3, 4, 5, 6, 8, 10, 12, 14, 15, 16, 18, 20, 22, 25};
.
.
.
void batt_func(){
  tft.print(ah_list[i]); //show Ah. on LCD 
  tft.setCursor(130,150);
  tft.println("Ah.");

}
.
.
.

//r_func() ---> higher Ah.:
void r_func(){  
  if(0 <= i < 14){
    ah_list[i++];
  }
  if(0 <= j < 14){
    time_list[j++];
  }  
}

//l_func() ---> lower Ah.:
void l_func(){
  if(0 < i < 15){
    ah_list[i--];
  }
  if(0 < j < 15){
    time_list[j--];
  }
}

for example after number 220 it shows another number if i press "right ( >> )" button, and similar for lower than number 12 !

Thanks for editing the Code Windows.

Draw a flowchart on paper.

Design your program to behave how you want.

Then implement each block.

You can study library examples for ideas. You can study the code. Adapt it for your project.
Ask questions if you need help.

I would start with simply jumping between 4 screens according to buttons. e.g. 4 different coloured screens.

Multi-dimensional arrays or arrays of structs are not difficult but I do not advise starting with them.

David.

david_prentice:
Draw a flowchart on paper.
Design your program to behave how you want.
Then implement each block. ---> i do it !

You can study library examples for ideas. You can study the code. Adapt it for your project.
Ask questions if you need help. ---> good idea

Multi-dimensional arrays or arrays of structs are not difficult but I do not advise starting with them. ---> it means i have to use typedef struct for my numbers? or not? which way is better for starting ?

David.

thanks !