#include <SPI.h>
#include <TFT_ILI9163C.h>
#define __CS 10
//#define __DC 6
//#define __RST 23
#define __DC 9
#define __RST 14
TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC, __RST);
// VIDEO SOURCE CODE HERE - Sumotoy ILI9163C
// https://forum.pjrc.com/threads/25862-ILI9163C-128x128-TFT-driver?p=104349&viewfull=1#post104349
// SPI SPEEDUP CODE HERE - Teensy-3-2-SPI-Clock-over-30-MHz
// https://forum.pjrc.com/threads/34406-Teensy-3-2-SPI-Clock-over-30-MHz?p=104374&viewfull=1#post104374
elapsedMillis timerEM;
elapsedMillis timerLimit;
char szAct[] = " |/-~\\|/-=\\";
char lastAction = 0;
int actionV = 0;
char szlsTest[5][15] = {"BIG888888", "small==", "```HI```", "...__lo__...", "BIG888888" };
uint16_t lsTestColor[5] = { CYAN, GREEN, RED, YELLOW, CYAN };
uint8_t lsTii = 0;
int16_t SkimX = 255, SkimY = 0;
int16_t RunX = 255, RunY = 0;
void tftSCprint( char *oldV, char *newV, uint16_t fgc, uint16_t bgc );
uint32_t tftSCprint( uint32_t oldV, uint32_t newV, uint16_t fgc, uint16_t bgc );
char tftSCprint( char oldV, char newV, uint16_t fgc, uint16_t bgc );
uint32_t MAXVAL = 10; // Set this to the number of milliseconds between screen updates
void setup() {
SIM_CLKDIV1 = SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV2(0) | SIM_CLKDIV1_OUTDIV4(3); //SIM_CLKDIV1_OUTDIV2(0) war auf 2!! // Good for OC Teensy less than 144 MHz
Serial.begin(38400);
while (!Serial && (millis() < 2000)) ;
tft.begin();
InicioLcd();
timerEM = 0;
}
int CountedLoops = 0;
uint32_t LastCountedLoops = 0;
uint32_t runseconds = 0xFFFFFFF0;
uint32_t old_LastCountedLoops = 0;
uint32_t old_runseconds = 0xFFFFF;
uint32_t old_val_timerEM = 0;
bool screenCleared = true;
void loop(void) {
if ( MAXVAL < timerLimit ) {
if ( screenCleared ) {
tft.setTextColor(WHITE, BLACK);
tft.setCursor(5, 3);
tft.print("Run Secs=");
tft.getCursor(RunX, RunY);
}
if (old_runseconds != runseconds) {
if ( 250 > RunX ) {
tft.setCursor(RunX, RunY);
old_runseconds = tftSCprint( old_runseconds, runseconds, WHITE, BLACK );
}
if ( 250 > SkimX ) {
tft.setCursor( SkimX, SkimY );
tft.setTextColor(WHITE, BLACK);
uint8_t old_lsTii = lsTii++;
tftSCprint( szlsTest[old_lsTii], szlsTest[lsTii], lsTestColor[lsTii], BLACK );
if (3 < lsTii) lsTii = 0;
}
}
if ( screenCleared ) {
tft.setTextColor(WHITE, BLACK);
tft.setCursor(45, 30);
tft.println("Todo OK");
tft.println("Reposiciones");
}
if ( !( CountedLoops % 8)) {
tft.setCursor(114, 0);
tft.setTextScale(2);
lastAction = tftSCprint( lastAction, szAct[actionV], CYAN, BLACK );
tft.setTextScale(1);
if ( !szAct[++actionV] ) actionV = 1;
}
tft.setCursor(70, 40);
old_val_timerEM = tftSCprint( old_val_timerEM, timerEM, WHITE, BLACK );
tft.setCursor(0, 54);
tft.print("Skimmer ");
tft.getCursor(SkimX, SkimY);
if ( 1000 > timerEM )
CountedLoops++;
else {
timerEM = 0;
LastCountedLoops = CountedLoops;
runseconds++;
CountedLoops = 0;
Serial.print("LOOPS per sec =");
Serial.println(LastCountedLoops);
Serial.print("Run Secs=");
Serial.print(runseconds);
}
if ( old_LastCountedLoops != LastCountedLoops ) {
tft.setCursor(10, 100);
tft.setTextColor(WHITE, BLACK);
tft.print("LOOPS per sec =");
old_LastCountedLoops = tftSCprint( old_LastCountedLoops, LastCountedLoops, WHITE, BLACK );
}
timerLimit = 0;
}
screenCleared = false;
}
void InicioLcd() {
tft.clearScreen();
tft.setCursor(0, 0);
tft.setTextColor(WHITE, BLACK);
tft.setTextScale(1);
screenCleared = true;
}
// tft. Self Cleaning String print
void tftSCprint( char *oldV, char *newV, uint16_t fgc, uint16_t bgc ) {
int16_t xxt, yyt;
tft.getCursor(xxt, yyt); // xxt = tft.getCursorX(); yyt = tft.getCursorY();
tft.setTextColor(bgc, bgc);
//tft.setTextColor(RED, RED);
tft.print(oldV);
tft.setCursor(xxt, yyt);
tft.setTextColor(fgc, bgc);
tft.print(newV);
return;
}
uint32_t tftSCprint( uint32_t oldV, uint32_t newV, uint16_t fgc, uint16_t bgc ) {
int16_t xxt, yyt;
tft.getCursor(xxt, yyt); // xxt = tft.getCursorX(); yyt = tft.getCursorY();
tft.setTextColor(bgc, bgc);
tft.print(oldV);
tft.setCursor(xxt, yyt);
tft.setTextColor(fgc, bgc);
tft.print(newV);
return (newV);
}
char tftSCprint( char oldV, char newV, uint16_t fgc, uint16_t bgc ) {
int16_t xxt, yyt;
tft.getCursor(xxt, yyt); // xxt = tft.getCursorX(); yyt = tft.getCursorY();
tft.setTextColor(bgc, bgc);
tft.print(oldV);
tft.setCursor(xxt, yyt);
tft.setTextColor(fgc, bgc);
tft.print(newV);
return (newV);
}