GLCD progress bar

I'm stuck with this. Please help. Equipment is 7" coldtears glcd/touchscreen with arduino mega and UTFT library. I need a code example for a vertical progress bar from an analog input pin. Currently I have a static vertical line with a rectangle representing data from the adc. It works fine but a progress bar would be so much better. The bar would indicate a microwave receiver signal level from an analog pin. The level comes from a 5 volt agc output from the receiver.

Thanks

Please post your current program or a smaller but complete one that shows what you are currently doing.

If you already have a rectangle representing the level cannot you simply extend it down to the bottom of the line ?

Making the rectangle larger didn't help. The resolution steps were to large and the rectangle simply erased itself. Need some way to make a progress bar reflect the analog pin voltage such that the top of the bar indicates the current adc level.

// Setup AGC Bar
int AGC = analogRead(A10); //
int AGClevel = map(AGC,0,1023,365,170); //map to GLCD y values for the bar

// Code to write over unused AGC line
static int oldAGClevel; // store old in memory - never changes value
if (oldAGClevel != AGClevel) //
{
myGLCD.setColor(0, 0, 0); // Set color to black to overwrite thus erase old AGC rectangle marker
myGLCD.fillRect(765,oldAGClevel,790,oldAGClevel+16); //setup AGC filled rectangle size (x1,y1,x2,y2) to black to overwrite old values

}

if (AGClevel < 250 ) // When AGClevel is < 250 marker rectangle becomes green
{
myGLCD.setColor(0,255,0); // set pan marker color to green (R, G, B)
myGLCD.fillRect(765,AGClevel,790,AGClevel+16); //create marker rectangle

}

if (AGClevel > 250 ) // When AGClevel is > 250 marker rectangle becomes red
{
myGLCD.setColor(255,0,0); // set pan marker color to green (R, G, B)
myGLCD.fillRect(765,AGClevel,790,AGClevel+16); // create AGC filled rectangle marker with red color (x1, y1, x2, y2)

}
oldAGClevel=AGClevel; //set current AGC level so the current level is displayed - not erased

// Draw AGC vertical line
myGLCD.setColor(255, 255, 255); // make color white (R, G, B)
myGLCD.setBackColor(0, 0, 0); // Background color is Black
myGLCD.drawLine(778, 160, 778, 380); // Draw vertical line at indicated position (x1, y1, x2, y2)

// Draw AGC line horizontal increments - a fancy look
for (int i=170; i<380; i+=10) // calculate y position of lines beginning at 100 and ending at 400 in steps of 10
myGLCD.drawLine(765, i, 790, i); // Draw x coordinate from 595 to 605 and y coordinates from "for" statement

The resolution steps were to large

Can you make them smaller ?

and the rectangle simply erased itself.

I bet it had some help from the program.

A line and different size rectangles were tried and all worked well but I need a progress bar but don't know how to make it.

Thanks

Make a rectangle that will be the outline, then use the drawHLine function and a little logic.

If the current value is smaller then the last value, make the line one color, otherwise make it the background color. Move the line accordingly to the analog pin.

Use for loops or if statements to smooth out the animation.

randee01:
A line and different size rectangles were tried and all worked well but I need a progress bar but don't know how to make it.

It sounds like you know how to make a rectangle.

What determines the height and width of the rectangle ?
This seems to draw the rectangle in the code you posted

myGLCD.fillRect(765,AGClevel,790,AGClevel+16); // create AGC filled rectangle marker with red color (x1, y1, x2, y2)

although the comments do not match the variables used in the code. The comments seem to imply that the fourth parameter sets the height of the rectangle and the values in the code would seem to me to draw a rectangle 16 pixels high.

Try this in your code

myGLCD.fillRect(765,100,790,AGClevel);

What size rectangle do you get ?

Thats right (x1,y1,x2,y2). Works fine. (AGClevel,AGClevel+16) also is used to blank old values when AGClevel != to oldAGClevel. The x value is fixed at a horiizontal value of 25 at location 765 to 790 on the display. and like you said the y is changed in this case by y2 = (AGC+16). It works with rectangles or lines but can't do a bar that way so far. So it will make a nice indicator but a progress would be better. Also the level changes between red and green indicating an acceptable signal level.

The first two lines

int AGC = analogRead(A10);
int AGClevel = map(AGC,0,1023,365,170);

//maps the ADC output to the GLCD vertical (y value) range of the GLCD AGC bar.

Saw some code for a LCD progress bar using "move" but that didn't to work.

Thanks

It works with rectangles or lines but can't do a bar that way

Sorry, I don't get that. A bar is just a filled rectangle.

Well,
Yes I agree a bar is just a filled rectangle. I'm just using the AGC +16 statement to add a fixed height (16) to the rectangle. It may not be the right way to do it. Also using map to define an coordinate and y coordinate that sort of locates the area on the display where the bar is located (trial and error). Then using the variable AGC (AGClevel) to change the y value to move the rectangle (or line) up and down as the AGC (analog A10) changes value. That may not be what you are asking about. Don't have any idea about how to construct a bar other than making a single line or single rectangle that moves up and down.

I am not sure about your "base level" (that is, the largest value for the Y axis for your bar) - I believe it is 365 based on your mapping - but later you talk about "400" - so I went with the larger value - alter it as you see fit...

Anyhow - you actually want to draw two bars - one representing the bar, the other the "clear area" above the bar - like so:

static int lastAGClevel;

// Setup AGC Bar
int AGC = analogRead(A10);
int AGClevel = map(AGC,0,1023,400,170); // map to AGC value to GLCD y values for the bar
  
// Draw the bar if the level changes
if (AGClevel != lastAGClevel) {
  myGLCD.setColor(0,0,0); // set color to background color (R, G, B)
  myGLCD.fillRect(765,170,790,AGClevel); // draw clearing rectangle

  myGLCD.setColor(0,255,0); // set color of bar to green (R, G, B)
  myGLCD.fillRect(765,AGClevel,790,400); // draw bar rectangle

  // Draw AGC line horizontal increments
  for (int i=170; i<390; i+=10) {
    myGLCD.drawLine(765, i, 790, i);
  }

  lastAGClevel = AGClevel;
}

Something like that, I think...?

Also - your comments in your code don't match what the code is actually doing - so it is very difficult for me to know exactly how big the bar should be, where it is actually positioned, how tall it is, what its minimum and maximum Y values are supposed to be, etc. Which is where my first sentence came from...

Fix this - it will help us, and you.

I'm just using the AGC +16 statement to add a fixed height (16) to the rectangle.

That maybe OK for the top of the rectangle (why +16 though) but for a progress bar the lower end will not change. This will allow the rectangle to grow upwards instead of just moving a fixed size rectangle up.

I do not have the same hardware as you so cannot try anything specific and can only comment on the general principles of how it might work.

EDIT Again, I for got to change the 100 to 1023. sorry.

Give this a try. (not tested)

Ex. V****Bar(analogRead(A0), 10, 10, 30, 100, 0xF800, 0x0);

void VBar(int val, int X1, int Y1, int X2, int Y2, unsigned int C1, unsigned int C2)
{
  int T = map(val, 0, 1023, Y2, Y1);
  for (int Y = Y2; Y >= Y1; Y--)
  {
    myGLCD.setColor((Y >= T) ? C1 : C2);
    myGLCD.drawHLine(X1, Y, X2 - X1);
  }
}

void HBar(int val, int X1, int Y1, int X2, int Y2, unsigned int C1, unsigned int C2)
{
  int T = map(val, 0, 1023, X1, X2);
  for (int X = X1; X >= X2; X--)
  {
    myGLCD.setColor((X >= T) ? C1 : C2);
    myGLCD.drawHLine(X, Y1, Y2 - Y1);
  }
}

I'm sorry. It wouldn't work. It did draw a few lines near the bottom of the display.
This had to be changed to use UTFT library.
int Y2=365;
int Y1=170;
int T = map(AGC,0,1023,Y2,Y1) to int AGClevel = map(AGC,0,1023,Y2,Y1);
for (int Y=Y2;Y>=Y1;Y--)
{
myGLCDsetColor(0,255,0); // for color green
myGLCDdrawLine(765,Y,X2-X1,Y);

Then your UTFT library is out of date. I took those functions from my TFT Extension library (made them into individual functions) which is designed to use the UTFT library.

On the other hand, you could have a modified version of the UTFT library that only works with your display. If that is the case, then you might be stuck with the library you have now and won't be able to update it.

These are the libraries used so far:

#include <UTFT.h> //UTFT library Electronics - Henning Karlsen
#include <UTouch.h> // UTouch library Electronics - Henning Karlsen
#include <UTFT_Buttons.h> // UButtons library Electronics - Henning Karlsen
#include <TFT_Extension.h> //TFT Library GitHub - AndrewMascolo/TFT_Extension: TFT Extension

What is needed?

I really appreciate all the help!

If you're using my TFT Extension library, then why not use the Bargraph functions from it?

Also why mix my buttons with the ones from the UTFT_Button library?

Thanks!. I started with UTFT awhile back but found it didn't have all that was needed. Forgot what was missing but your library solved the problem. Think it was the buttons - not sure. I'll do some reading and look at your bargraph.

You should have a Bargraph example sketch too.

Hi,
I couldn't find a bargraph example but did read about it in the documents file. It mentioned TL and BR but nothing about the command arguments.

I tried running the vertical slider example but it won't compile.
The compile errors are:

Arduino: 1.6.3 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Build options changed, rebuilding all

Using library UTFT in folder: C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT (legacy)

Using library Utouch in folder: C:\Users\Owner\Favorites\Documents\Arduino\libraries\Utouch (legacy)

Using library TFT_Extension in folder: C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension (legacy)

C:\Users\Owner\AppData\Roaming\Arduino15\packages\arduino\tools\avr-gcc\4.8.1-arduino2/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10603 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Users\Owner\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.2\cores\arduino -IC:\Users\Owner\AppData\Roaming\Arduino15\packages\arduino\hardware\avr\1.6.2\variants\mega -IC:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT -IC:\Users\Owner\Favorites\Documents\Arduino\libraries\Utouch -IC:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension C:\Users\Owner\AppData\Local\Temp\build4713459259570123432.tmp\SliderBar_Vertical.cpp -o C:\Users\Owner\AppData\Local\Temp\build4713459259570123432.tmp\SliderBar_Vertical.cpp.o

SliderBar_Vertical.ino:8:34: error: no matching function for call to 'UTFT::UTFT(int, int, double, int)'

SliderBar_Vertical.ino:8:34: note: candidates are:

In file included from SliderBar_Vertical.ino:1:0:

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:201:3: note: UTFT::UTFT(byte, int, int, int, int, int)

UTFT(byte model, int RS, int WR, int CS, int RST, int SER=0);

^

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:201:3: note: candidate expects 6 arguments, 4 provided

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:200:3: note: UTFT::UTFT()

UTFT();

^

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:200:3: note: candidate expects 0 arguments, 4 provided

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:197:7: note: UTFT::UTFT(const UTFT&)

class UTFT

^

C:\Users\Owner\Favorites\Documents\Arduino\libraries\UTFT/UTFT.h:197:7: note: candidate expects 1 argument, 4 provided

SliderBar_Vertical.ino:11:49: error: no matching function for call to 'TFT_Extension::TFT_Extension(UTFT*, UTouch*, int)'

SliderBar_Vertical.ino:11:49: note: candidates are:

In file included from SliderBar_Vertical.ino:3:0:

C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension/TFT_Extension.h:128:5: note: TFT_Extension::TFT_Extension(UTFT*, UTouch*)

TFT_Extension(UTFT *Disp, UTouch *Touch);

^

C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension/TFT_Extension.h:128:5: note: candidate expects 2 arguments, 3 provided

C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension/TFT_Extension.h:125:7: note: TFT_Extension::TFT_Extension(const TFT_Extension&)

class TFT_Extension

^

C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension/TFT_Extension.h:125:7: note: candidate expects 1 argument, 3 provided

Multiple libraries were found for "TFT_Extension.h"

Used: C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension

Not used: C:\Users\Owner\Favorites\Documents\Arduino\libraries\libraries

Not used: C:\Users\Owner\Favorites\Documents\Arduino\libraries\TFT_Extension-master

Error compiling.

vertical slider bar code is:

#include <UTFT.h>
#include <UTouch.h>
#include <TFT_Extension.h>
// Declare which fonts we will be using
extern uint8_t SmallFont[];

//myGLCD(RS,WR,CS,RST,ALE,mode);
UTFT myGLCD(CTE70CPLD,38,39.40,41);
//myTouch(TCLK,TCS,DIN,DOUT,IRQ);
UTouch myTouch(6,5,4,3,2);
TFT_Extension myTFT(&myGLCD, &myTouch, LANDSCAPE);
#define convert(x) {myTFT.ConvertRGB(x)}
void setup()
{
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_LOW);
myGLCD.fillScr(WHITE);
}

void loop()
{
//(X1, Y1, X2, Y2, ID Number, Color)
byte red = map(myTFT.VertSlider(20, 20, 50, 210, 0, RED), 0, 100, 0, 255);
byte green = map(myTFT.VertSlider(70, 20, 100, 210, 1, GREEN), 0, 100, 0, 255);
byte blue = map(myTFT.VertSlider(120, 20, 150, 210, 2, BLUE), 0, 100, 0, 255);

myGLCD.setColor(WHITE);
myGLCD.printNumI(red, 20, 10);
myGLCD.printNumI(green, 70, 10);
myGLCD.printNumI(blue, 120, 10);

myGLCD.setColor(red, green, blue);
myGLCD.fillRect(200, 10, 250, 60);
}