first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

273
TFT_TEST2/TFT_TEST2.ino Executable file
View File

@@ -0,0 +1,273 @@
/* Arduino TFT Tutorial
* Program made by Dejan Nedelkovski,
* www.HowToMechatronics.com
*/
/* This program uses the UTFT and UTouch libraries
* made by Henning Karlsen.
* You can find and download them at:
* www.RinkyDinkElectronics.com
*/
#include <UTFT.h>
#include <UTouch.h>
//==== Creating Objects
UTFT myGLCD(SSD1289,38,39,40,41); //Parameters should be adjusted to your Display/Schield model
UTouch myTouch( 6, 5, 4, 3, 2);
//==== Defining Variables
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
int x, y;
char currentPage, selectedUnit;
//Ultrasonic Sensor
const int VCC = 13;
const int trigPin = 11;
const int echoPin = 12;
long duration;
int distanceInch, distanceCm;
// RGB LEDs
const int redLed = 10;
const int greenLed = 9;
const int blueLed = 8;
int xR=38;
int xG=38;
int xB=38;
//// Floppy Bird
//int xP = 319;
//int yP = 100;
//int yB = 30;
//int fallRateInt = 0;
//float fallRate =0;
//int score=0;
const int button = 14;
//int buttonState = 0;
void setup() {
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
// Defining Pin Modes
pinMode(VCC, OUTPUT); // VCC
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(button, INPUT);
digitalWrite(VCC, HIGH); // +5V - Pin 13 as VCC
drawHomeScreen(); // Draws the Home Screen
currentPage = '0'; // Indicates that we are at Home Screen
selectedUnit = '0'; // Indicates the selected unit for the first example, cms or inches
}
void loop() {
// Home Screen
// if (currentPage == '0') {
// if (myTouch.dataAvailable()) {
// myTouch.read();
// x=myTouch.getX(); // X coordinate where the screen has been pressed
// y=myTouch.getY(); // Y coordinates where the screen has been pressed
//
// // If we press the RGB LED Control Button
// if ((x>=35) && (x<=285) && (y>=140) && (y<=180)) {
// drawFrame(35, 140, 285, 180);
// currentPage = '2';
// myGLCD.clrScr();
// drawLedControl();
// }
// }
// }
// // RGB LED Control
// if (currentPage == '2') {
// setLedColor();
// if (myTouch.dataAvailable()) {
// myTouch.read();
// x=myTouch.getX();
// y=myTouch.getY();
//
// //Back button
// if ((x>=10) && (x<=60) &&(y>=10) && (y<=36)) {
// drawFrame(10, 10, 60, 36);
// currentPage = '0';
// myGLCD.clrScr();
// drawHomeScreen();
// // Turns the LED off
// analogWrite(redLed, 0);
// analogWrite(greenLed, 0);
// analogWrite(blueLed, 0);
// }
// }
// }
}
// ====== Custom Funtions ======
// drawHomeScreen - Custom Function
void drawHomeScreen() {
// Title
myGLCD.setBackColor(0,0,0); // Sets the background color of the area where the text will be printed to black
myGLCD.setColor(255, 255, 255); // Sets color to white
myGLCD.setFont(BigFont); // Sets font to big
myGLCD.print("Arduino TFT Tutorial", CENTER, 10); // Prints the string on the screen
myGLCD.setColor(255, 0, 0); // Sets color to red
myGLCD.drawLine(0,32,319,32); // Draws the red line
myGLCD.setColor(255, 255, 255); // Sets color to white
myGLCD.setFont(SmallFont); // Sets the font to small
myGLCD.print("by HowToMechatronics.com", CENTER, 41); // Prints the string
myGLCD.setFont(BigFont);
myGLCD.print("Select Example", CENTER, 64);
// Button - Distance Sensor
myGLCD.setColor(16, 167, 103); // Sets green color
myGLCD.fillRoundRect (35, 90, 285, 130); // Draws filled rounded rectangle
myGLCD.setColor(255, 255, 255); // Sets color to white
myGLCD.drawRoundRect (35, 90, 285, 130); // Draws rounded rectangle without a fill, so the overall appearance of the button looks like it has a frame
myGLCD.setFont(BigFont); // Sets the font to big
myGLCD.setBackColor(16, 167, 103); // Sets the background color of the area where the text will be printed to green, same as the button
myGLCD.print("DISTANCE SENSOR", CENTER, 102); // Prints the string
// Button - RGB LED Control
myGLCD.setColor(16, 167, 103);
myGLCD.fillRoundRect (35, 140, 285, 180);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (35, 140, 285, 180);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(16, 167, 103);
myGLCD.print("RGB LED CONTROL", CENTER, 152);
// Button - Birduino
myGLCD.setColor(16, 167, 103);
myGLCD.fillRoundRect (35, 190, 285, 230);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (35, 190, 285, 230);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(16, 167, 103);
myGLCD.print("BIRDUINO GAME", CENTER, 202);
}
// Highlights the button when pressed
void drawFrame(int x1, int y1, int x2, int y2) {
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
//====================================================
void drawLedControl() {
// myGLCD.setColor(100, 155, 203);
// myGLCD.fillRoundRect (10, 10, 60, 36);
// myGLCD.setColor(255, 255, 255);
// myGLCD.drawRoundRect (10, 10, 60, 36);
// myGLCD.setFont(BigFont);
// myGLCD.setBackColor(100, 155, 203);
// myGLCD.print("<-", 18, 15);
// myGLCD.setBackColor(0, 0, 0);
// myGLCD.setFont(SmallFont);
// myGLCD.print("Back to Main Menu", 70, 18);
// myGLCD.setFont(BigFont);
// myGLCD.print("RGB LED Control", CENTER, 50);
// myGLCD.print("LED Color:", 10, 95);
// myGLCD.print("R", 10, 135);
// myGLCD.print("G", 10, 175);
// myGLCD.print("B", 10, 215);
// myGLCD.setColor(255, 0, 0);
// myGLCD.drawLine(0,75,319,75);
// myGLCD.setColor(255, 255, 255);
// myGLCD.drawRect(30, 138, 310, 148); // R - Slider
// myGLCD.drawRect(30, 178, 310, 188);
// myGLCD.drawRect(30, 218, 310, 228);
}
//====================================================
//============= setLedColor() - Custom Funtion
void setLedColor() {
// if (myTouch.dataAvailable()) {
// myTouch.read();
// x=myTouch.getX();
// y=myTouch.getY();
// // Area of the Red color slider
// if( (y>=130) && (y<=156)) {
// xR=x; // Stores the X value where the screen has been pressed in to variable xR
// if (xR<=38) { // Confines the area of the slider to be above 38 pixels
// xR=38;
// }
// if (xR>=303){ /// Confines the area of the slider to be under 310 pixels
// xR=303;
// }
// }
// // Area of the Green color slider
// if( (y>=170) && (y<=196)) {
// xG=x;
// if (xG<=38) {
// xG=38;
// }
// if (xG>=303){
// xG=303;
// }
// }
// // Area of the Blue color slider
// if( (y>=210) && (y<=236)) {
// xB=x;
// if (xB<=38) {
// xB=38;
// }
// if (xB>=303){
// xB=303;
// }
// }
// }
// // Maps the values of the X - Axis from 38 to 0 and 310 to 255, because we need values from 0 to 255 for turning on the led
// int xRC = map(xR,38,310,0,255);
// int xGC = map(xG,38,310,0,255);
// int xBC = map(xB,38,310,0,255);
//
// // Sends PWM signal to the pins of the led
// analogWrite(redLed, xRC);
// analogWrite(greenLed, xGC);
// analogWrite(blueLed, xBC);
//
// // Draws a rectangle with the latest color combination
// myGLCD.setColor(xRC, xGC, xBC);
// myGLCD.fillRoundRect(175, 87, 310, 119);
//
// // Draws the positioners
// myGLCD.setColor(255, 255, 255);
// myGLCD.fillRect(xR,139,(xR+4),147); // Positioner
// myGLCD.setColor(xRC, 0, 0);
// myGLCD.fillRect(31, 139, (xR-1), 147);
// myGLCD.setColor(0, 0, 0);
// myGLCD.fillRect((xR+5), 139, 309, 147);
//
// myGLCD.setColor(255, 255, 255);
// myGLCD.fillRect(xG,179,(xG+4),187);
// myGLCD.setColor(0, xGC, 0);
// myGLCD.fillRect(31, 179, (xG-1), 187);
// myGLCD.setColor(0, 0, 0);
// myGLCD.fillRect((xG+5), 179, 309, 187);
//
//
// myGLCD.setColor(255, 255, 255);
// myGLCD.fillRect(xB,219,(xB+4),227);
// myGLCD.setColor(0, 0, xBC);
// myGLCD.fillRect(31, 219, (xB-1), 227);
// myGLCD.setColor(0, 0, 0);
// myGLCD.fillRect((xB+5), 219, 309, 227);
}