#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
const byte TFT_RST = 7;
const byte TFT_DC = 9;
const byte TFT_CS = 10;
byte X = 20;
byte Y = 30;
byte W = 200;
byte H = 60;
byte progress = 0;
byte progressRead = 0;
const unsigned long runTime = 10000;
const unsigned long progInc = 20;
unsigned long runTimeCheck;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void setup()
{
Serial.begin(9600);
Serial.println("ILI9341 bargraph Test!");
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.println(" Purge Time");
tft.drawRect(X, Y, W, H, ILI9341_WHITE);
runTimeCheck = 0;
}
void loop(void)
{
barProgress();
}
void barProgress()
{
static unsigned long timer = 0;
unsigned long interval = runTime/progInc*2;
if (millis() - timer >= interval)
{
timer = millis();
tft.fillRect(X, Y, progress+progInc, H, ILI9341_WHITE);
tft.setCursor(10, 100);
tft.print("Progress = ");
tft.fillRect(130, 100, 100, 200, ILI9341_BLACK); // erase old data
tft.setCursor(140, 100);
progressRead = (progress+progInc)/2;
tft.println(progressRead);
tft.setCursor(10, 120);
tft.print("Run Time = ");
tft.setCursor(140, 120);
tft.println(runTimeCheck+interval);
runTimeCheck += interval;
progress += progInc;
if(progress > 180)
{
while (1); // finished just wait. Take this out for your use.
// or reset the numbers for another go
}
}
}