TFT bar graph

Hi, im a newbie here and im trying to do a project similar to the LEDBarGraph which turns on a series of LEDs based on the value of an analog sensor. However, instead of using LEDs, i would like to plot the bar graph in the TFT LCD screen.
Im using arduino pro mini.
The attached photo is the TFT LCD im using.

I couldn’t find any code similar to what i want to do… Can somebody give me some idea on the code please?
Thanks in advance!

sff.jpg

What have you managed to do with the TFT so far ? Can you set and unset pixels on it, or maybe turn a block of pixels on and off ?

I've only managed to print strings and also display an image on the TFT. I have not tried turning on and off the pixels yet..

What library are you using ? I would expect it to provide functions to draw primitive shapes such as lines and circles and to turn blocks of pixels on and off. In the case of a bar graph, turning on a block of pixels would to equivalent to turning on an LED but you will be able to get much finer resolution using the TFT display.

I am using the TFT library.
#include <TFT.h>
I think this library is able to provide functions to draw lines or circles… However, i have no idea on how to turn a pixel on and off…

Take a look at the documentation for point & rect here: http://arduino.cc/en/Reference/TFTLibrary

Thanks for that documentation!
But still, i don’t really get the idea of plotting a bar graph using analog values on the tft lcd screen…
I want to make it like the photo i attached but in the TFT screen…

hqdefault.jpg

I'd start by drawing a rectangle and make the width proportional to the value you get from analogRead. Just divide the reading by 7 to get the width into the range of the pixels available on the display.

You'll need to clear the rectangle and redraw it when the reading changes or smaller values won't show the right size bar.

Hi dear all!
I’ve found a nice bar graph here
and I want to add another Analog Input to make the second separate bar on the dispaly, thus A0 and A1 values to be indicated on two separate bars. I’ve tried to rationally “duplicate” parts of the sketch giving different names to constants and functions for A0 and A1 inputs, but I get two 100% equal bar graphs, that read only A0.
Any help will be appreciated!

The original code is:

// Henry's Bench
//  Basic Bargraph Tutorial

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>

#define CS 10
#define DC 9

// Declare an instance of the ILI9163
TFT_ILI9163C tft = TFT_ILI9163C(CS, 8, DC); 


// Color Pallette

#define BACKCOLOR 0x18E3
#define BARCOLOR 0x0620
#define SCALECOLOR 0xFFFF

//Analog Measurement Declarations
const int analogIn = A0;
int RawValue = 0;
int LastPercent = 0;
 

void setup() {
  tft.begin();
  tft.fillScreen(BACKCOLOR);
  drawScale(); 
}

void loop(){  
    int newPercent;
    RawValue = analogRead(analogIn);
    newPercent = int((RawValue/1024.0)* 100.0);
    
    if (newPercent != LastPercent){
      drawBar(newPercent);     
    }
     
}

void drawScale(){  
  tft.drawFastVLine(55, 20,100, SCALECOLOR ); // Vertical Scale Line  
  tft.drawFastHLine(47, 20, 8, SCALECOLOR); // Major Division
  tft.drawFastHLine(50, 44, 5, SCALECOLOR); // Minor Division
  tft.drawFastHLine(47, 69, 8, SCALECOLOR); // Major Division
  tft.drawFastHLine(50, 94, 5, SCALECOLOR); // Minor Division
  tft.drawFastHLine(47, 119, 8, SCALECOLOR);  // Major Division
}


void drawBar (int nPer){

  if(nPer < LastPercent){
    tft.fillRect(61, 20 + (100-LastPercent), 30, LastPercent - nPer,  BACKCOLOR);     
  }
  else{
    tft.fillRect(61, 20 + (100-nPer), 30, nPer - LastPercent,  BARCOLOR);
  }    
  LastPercent = nPer;  
  
}

Hi dear all! It seems to me I've solved the problem! In my case I didn't [u]physically[/u] connect the potentiometer to A1 pin, so (it could seem a little bit starnge), the indicated values were equal, A0=A1, and the graphs showed the same value. When I connected the second potentiometer to A1 it started to work as expected. I'll try to check it again on another Arduino UNO, using a simplier sketch for testing.