Here is all the code
A bit messy as I have playing around a bit with TFT screen stuff.
BTW, with all the code in the complete loop time is about 1/2 second, ie drawing the sine, cosine and tangent on the screen.
// UTFT_Demo_320x240 (C)2014 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library.
//
#include <UTFT.h>
//#include <UTouch.h>
// 16 bit interface pin numbers
//ITDB02 ( D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15, RS, WR, CS, RST)
//ITDB02 lcd(37, 36, 35, 34, 33, 32, 31, 30, 22, 23, 24, 25, 26, 27, 28, 29, 38, 39, 40, 41);
//Heart Beat LED
int led = 13;
int ledState = 0;
//Global Variables
unsigned long gettime_Millis = 0;
unsigned long newtimeMillis = 0;
unsigned long timelapseMillis = 0;
unsigned long numbertoshow = 0;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
// Set the pins to the correct ones for your development shield
// ------------------------------------------------------------
// Arduino Uno / 2009:
// -------------------
// Standard Arduino Uno/2009 shield : <display model>,A5,A4,A3,A2
// DisplayModule Arduino Uno TFT shield : <display model>,A5,A4,A3,A2
//
// Arduino Mega:
// -------------------
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Mega : <display model>,38,39,40,41
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ITDB32S,38,39,40,41); // RS,WR,CS,RST
// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due : 6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
/*
UTouch myTouch( 6, //Pin for Touch Clock (D_CLK)
5, //Pin for Touch Chip Select (D_CS)
4, //Pin for Touch Data input (D_DIN)
3, //Pin for Touch Data output (D_OUT)
2); //Pin for Touch IRQ (DPenirq)
*/
void setup()
{
pinMode(led, OUTPUT);
//myTouch.InitTouch();
//myTouch.setPrecision(PREC_MEDIUM);
SetupLCD();
DrawBaseScreen();
DrawScreen();
}
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
void loop()
{
//start timer
gettime_Millis = millis();//micros();
DrawScreen1();
HeartBeat(); //speed test.Frequency should tell how fast we do a round trip
//Calculate time taken to a loop
newtimeMillis = millis();//micros();
timelapseMillis = newtimeMillis-gettime_Millis;
//need a bit time to see the result
delay(1000);
}
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
//-------------------------------------------------------
void HeartBeat(void)
{
ledState = !ledState;
digitalWrite(led, ledState);
}
//-------------------------------------------------------------------------
void DrawBaseScreen(void)
{
// Clear the screen and draw the frame
myGLCD.clrScr();
myGLCD.setColor(255, 0, 0);
myGLCD.fillRect(0, 0, 319, 13);
myGLCD.setColor(64, 64, 64);
myGLCD.fillRect(0, 226, 319, 239);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(255, 0, 0);
myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
myGLCD.setBackColor(64, 64, 64);
myGLCD.setColor(255,255,0);
myGLCD.print("* V5 *", CENTER, 227);
DrawMinorBackground();
DrawCrossHair();
}
//----------------------------------------------------------------
void DrawMinorBackground(void)
{
myGLCD.setColor(0, 0, 255);
myGLCD.drawRect(0, 14, 319, 225);
myGLCD.fillRect(0, 14, 319, 225);
}
//----------------------------------------------------------------
void DrawCrossHair(void)
{
// Draw crosshairs
myGLCD.setColor(0, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(159, 15, 159, 224);
myGLCD.drawLine(1, 119, 318, 119);
for (int i=9; i<310; i+=10)
myGLCD.drawLine(i, 117, i, 121);
for (int i=19; i<220; i+=10)
myGLCD.drawLine(157, i, 161, i);
}
//--------------------------------------------------------------
void DrawScreen(void)
{
//DrawMinorBackground();
//DrawCrossHair();
myGLCD.setBackColor(VGA_BLUE); // Set the background color to blue behind the text following below
/*
// Draw sin-, cos- and tan-lines
myGLCD.setColor(0,255,255);
myGLCD.print("Sin", 5, 15);
/*for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
// delay(3);
}
myGLCD.setColor(255,0,0);
myGLCD.print("Cos", 5, 27);
/*for (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
// delay(3);
}
myGLCD.setColor(255,255,0);
myGLCD.print("Tan", 5, 39);
/*r (int i=1; i<318; i++)
{
myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
// delay(3);
}
*/
myGLCD.setColor(255,255,0);
myGLCD.print("Time mS", 5, 55);
numbertoshow = timelapseMillis;
myGLCD.printNumI(numbertoshow,80,55);
}
void DrawScreen1 (void)
{
numbertoshow = timelapseMillis;
myGLCD.printNumI(numbertoshow,80,55);
}
//---------------------------------------
void SetupLCD(void)
{
// Sets up the LCD
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
}