Go Down

Topic: New TFT Extension Library (Read 65033 times) previous topic - next topic


ok im pulling data from a megasquirt ecu via serial, i trying to make a display to show various information from the engine sensors connected to that, for instance using the slider like a bar graph to display throttle the throttle. 


Oh ok, so the other way around, instead of being a slider, you want a bar graph. Yea I can do that.


Ah that would rock, just tried your update and its working good tried with 4 gauges on the screen, had them all reading from a 10k pot  all working good thanks. i did try it before with just one gauge and it worked on pulling the data via serial and displaying it on the gauge as well


May 18, 2014, 02:08 am Last Edit: May 18, 2014, 02:31 am by HazardsMind Reason: 1
Library is updated with new functions, HorBarGraph and VertBarGraph. Go back to previous post and re-download.
Look at Horizontal_BarGraph example to see how it is used.

I also added your username to the .h file.


oh got it that rocks, with those additions gives me just what i need to continue with my project.


been playing about with this some more, i'm using a switch case from a push button input to change between 3 different pages i want it to draw that works, first page just basic prints to the screen of the sensor readings, push button then page 2 so far i'm using drawgauge to draw 2 gauges one for engine rpm and the second for throttle 0-100% they work its a bit slow drawing them at  first but the needle movements are quick enough after the back ground has drawn to the screen not to much of a biggie, then page3 will be some bar graphs ect not got that far yet though. the issue im having if you cycle from page 1,2,3 back to 1 then the second time on to page 2 the backgrounds don't get drawn only the needles part of the gauges.   



Would you mind sharing some of your switch case code? I am wanting to learn how to put the buttons and gauges to use but, I haven't figured it out yet.


May 19, 2014, 01:55 pm Last Edit: May 19, 2014, 01:58 pm by HazardsMind Reason: 1
Ok, I can make a quick function to allow you to repaint the gauge.

Function: ResetGauge( byte _ID ), This should go in the next and previous pages of the gauge. So if your gauges are on page 2, then this function needs to be in pages 1 and 3. So when you go back to page 2, the gauge will be repainted.

Library added below.


wicked il give that a go and report back thanks again, this is a basic striped down version of how i'm drawing the pages.
Code: [Select]
  #include <UTFT.h>
#include <UTouch.h>
#include <memsaving.h>
#include <TFT_Extension.h>

extern uint8_t BigFont[];

UTFT myGLCD(SSD1289,38,39,40,41);
UTouch        myTouch(6,5,4,3,2);
TFT_Extension myTFT(&myGLCD, &myTouch, LANDSCAPE);

const int  buttonPin = A1;    // the pin that the pushbutton is attached to

int buttonPushCounter = 0;   // counter for the number of button presses
int ButtonState = 0;         // current state of the button
int lastState = 0;     // previous state of the button

void page1(){
  myGLCD.setColor(255, 0, 0);
  myGLCD.print(" page 1 ",CENTER, 80);
void page2(){
  myGLCD.setColor(0, 255, 0);
  myGLCD.print(" page 2 ",CENTER, 120);
void page3(){
  myGLCD.setColor(0, 0, 255);
  myGLCD.print(" page 3 ",CENTER, 150);

void setup() {
  pinMode(buttonPin, INPUT);
  myGLCD.setColor(0, 0, 255);
  myGLCD.print(" TEST ",CENTER, 1);


void loop() {
  ButtonState = digitalRead(buttonPin);

  if(ButtonState && ButtonState != lastState)  // button latch, no debounce needed.

    if(buttonPushCounter < 2) // This will check to see if the count is within a range of 0 - 2, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.

      buttonPushCounter += 1; // same as count = count + 1;

      buttonPushCounter = 0;

  lastState = ButtonState;

  switch (buttonPushCounter) {
  case 0:   
  case 1:   

  case 2:   


You could put the reset functions inside the case statements before you load the pages. Or you can put them inside the pages themselves, whichever is easier for you.


i put them in the case statements  for case 0 and 2 and now they re draw   :D :D


i was having a play with this again and run in to a problem the gauges were taking a long time to draw a couple of seconds maybe and this was sometimes causing me to loose sync  with the data form the ecu so i made a small edit to the library...

Code: [Select]

_Disp->fillCircle(pos_x, pos_y, rad);
//drawArc(pos_x, pos_y, rad, rad, start, stop, WHITE);
//drawArc(pos_x, pos_y, rad, 0, start, stop, BLACK);

does not look quite as cool but draws and re-draws super quick and you can still set the sweep angle for the gauge, hope you don't mind.


May 21, 2014, 01:41 am Last Edit: May 21, 2014, 08:12 pm by HazardsMind Reason: 1
If it helps you then that's fine. I will try to make it faster if I can.


Code: [Select]

  gauge[_ID].x = pos_x + sin((value-90) * deg_to_rad) * (rad-2);
  gauge[_ID].y = pos_y + cos((value-90) * deg_to_rad) * (rad-2);

you could remove the -90 from the formulas
Code: [Select]
sin(value -90)  =>  -cos(value)
cos(value-90)  => sin(value)

you might want to speed up the sin and cos like discussed here
- http://forum.arduino.cc/index.php?topic=69723.0 -
- http://forum.arduino.cc//index.php?topic=196625.msg1453433#msg1453433 -

make wrappers around  a (PROGMEM) lookup table that works in degrees
the code would become faster but longer.
(there are 31 places in your lib where you use sin( x * degtorad)  + 30 cos()  == 60 places to speed up.
so the extra bytes might be worth the performance  gain
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


If I have time, I will look into it, thanks robtillaart

Go Up