Bargraph problem

Dear all,
I have had some problem to understand a code from Github about a Bar-graph color bar.
When I use this code, the bars light up to the end and erase to the beginning in succession. This process repeats automatically. However I would like to use Bar-graph to read some variable, for example ultraviolet radiation level. How can I do this with this code. What changes need to be made?
I really thank you for any help…

Here is the code:

#include <UTFT.h>
UTFT myGLCD(SSD1963_480,38,39,40,41); //myGLCD(RS,WR,CS,RST,ALE,mode);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
byte rgbtable[34][3]{
void setup()
//drawColorBar(value 0-32, x coordinate of left of graph, y coordinate of top left corner of graph, size);
void drawColorBar(int value,int spotx, int spoty, int pix){
  for(int i=0;i<33;i++){
    } else {myGLCD.setColor(VGA_GRAY);}
 myGLCD.print("V: "+String(value)+"",spotx+(32*pix)+10,spoty+4);

void loop(){
      myGLCD.print("ARDUINO COLOR BAR COLD-HOT",0,0);
      myGLCD.print("FREE CODE AVAILABLE!",0,16);
  for(int i=0; i<33; i++){

myGLCD.print("SUBSCRIBE FOR MORE! ",0,16);
for(int i=32; i>=0; i--){



It's explained here:
drawColorBar(value 0-32, x coordinate of left of graph, y coordinate of top left corner of graph, size);The value you want to display (UV radiation level) should be translated in a scale from 0 to 32 (meaning the minimum value is translated to 0 and the maximum to 32). You can use the map function to do that.
Then you call the abovementionned drawColorBar function, with the arguments as explained.

Hi Lesept,

At first, thanks for your help.

I understand clear about the map and the scale. However, it is not clear to me how introduce the variable in the process. What stop this counters...Is that counters just a test set? or they are necessary to increase the variable?
Do I need to remove the counters?

I'm just a beginner on arduino codes.

Thanks a lot for your patience.


An arduino code is made of 3 parts :

  • Variables and libraries definition (head of the ino file)
  • The setup function, to define and do what you want done only once
  • The loop function which iterates forever.
    In the setup, you do all the definitions and initializations. There you have the instructions for the initial variables values, all the parts of the display that won't change, etc.
    In the loop, you do what is dynamic, such as sensor reading and display. So you must add some instructions in the loop to read the value from the sensor and call the drawColorBar to show the bar.

So your code will look like:

libraries declaration
constants declarations

void setup () {
  serial declaration and initialization
  initial values of global variables
  pin declarations
  display text or anything that won't change

void loop {
  read sensor value, put it in a variable (say X)
  map X to 0 - 32
  display the bar
  do whatever else you want

The loop will run forever, in a ... loop!

So forget the counters, they were in that piece of code for its own purpose. You just need to translate what I suggest above into C code.

Hi Lesept,

Now I understand. Thank you a lot for explain me...