TFT screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/JoaoLopesF/SPFD5408 | |
#include <SPFD5408_Adafruit_GFX.h> // Core graphics library | |
#include <SPFD5408TFTLCDLib.h> // Hardware-specific library | |
#include <SPFD5408_TouchScreen.h> // Touch Screen library | |
#define LCD_CS A3 // Chip Select goes to Analog 3 | |
#define LCD_CD A2 // Command/Data goes to Analog 2 | |
#define LCD_WR A1 // LCD Write goes to Analog 1 | |
#define LCD_RD A0 // LCD Read goes to Analog 0 | |
#define MINPRESSURE 10 | |
#define MAXPRESSURE 1000 | |
#define YP A1 // must be an analog pin, use "An" notation! | |
#define XM A2 // must be an analog pin, use "An" notation! | |
#define YM 7 // can be a digital pin | |
#define XP 6 // can be a digital pin | |
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin | |
// Assign human-readable names to some common 16-bit color values: | |
#define BLACK 0x0000 | |
#define BLUE 0x001F | |
#define RED 0xF800 | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
SPFD5408TFTLCDLib tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // for display | |
void setup(void) { | |
Serial.begin(9600); | |
tft.reset(); | |
tft.begin(0x9341); // SDFP5408 | |
tft.setRotation(1); // Need for the Mega, please changed for your choice or rotation initial | |
randomSeed(analogRead(1)); | |
tft.fillScreen(BLACK); | |
tft.setCursor(60,0); | |
tft.setTextSize(2); | |
tft.print("Made by ChoiLab"); | |
delay(1000); | |
tft.fillScreen(BLACK); | |
tft.setCursor(60,0); | |
tft.setTextSize(4); | |
tft.println("Made by"); | |
tft.println("ChoiLab"); | |
delay(1000); | |
tft.fillScreen(BLACK); | |
tft.setCursor(60,0); | |
tft.setTextSize(6); | |
tft.println("Made"); | |
tft.println("by"); | |
tft.println("ChoiLab"); | |
delay(1000); | |
} | |
void loop(void){ | |
int maximum_number_to_draw = 125; | |
tft.fillScreen(BLACK); | |
tft.setCursor(0, 0); | |
fillNumber(maximum_number_to_draw); | |
delay(2000); | |
} | |
void fillNumber(int max_target){ | |
int yoff = 25; // y offset | |
long seq = random(1, max_target); // target number | |
long row = random(0,5); // row to display target number | |
long col = random(1,8); // limit col into 1 ~ 7 : this option guarantee at least one white letter is present at each end. | |
int fillNum; // number of white digits to fill the row where target number is located | |
if (seq<10) | |
fillNum = 9; | |
else if (seq<100) | |
fillNum = 8; | |
else | |
fillNum = 7; | |
tft.setTextSize(5); | |
for(int j = 0; j<5; j++)// for each row | |
{ | |
tft.setCursor(10, 40*j+yoff); | |
if(row == j) // if target number is located | |
{ | |
tft.setTextColor(WHITE); | |
for(int k = 0; k < col; k++) // fill left | |
{ | |
tft.print(random(0,9)); | |
} | |
tft.print(seq); | |
tft.setTextColor(WHITE); | |
for(int k = 0; k < fillNum-col; k++) // fill right | |
{ | |
tft.print(random(0,9)); | |
} | |
} | |
else | |
{ | |
tft.setTextColor(WHITE); | |
tft.println(random(1000000000,9999999999)); | |
} | |
} | |
delay(3000); | |
tft.setCursor(10 + (30*col), 40*row+yoff); | |
tft.setTextColor(RED); | |
tft.print(seq); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment