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

160
TFT_GRAPH/TFT_GRAPH.ino Executable file
View File

@@ -0,0 +1,160 @@
//***THIS IS THE NEW VERSION THAT WORKS WITH THE NEW LIBRARIES!!!***
// TFTLCD.h and TouchScreen.h are from adafruit.com where you can also purchase a really nice 2.8" TFT with touchscreen :)
// 2012 Jeremy Saglimbeni - thecustomgeek.com
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_8bit_AS.h>// Hardware-specific library
#include <TouchScreen.h>
//#include <EEPROM.h>
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the tft paint example).
#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 LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
// These are the pins for the shield!
#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
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// Color definitions - in 5:6:5
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TEST 0x1BF5
Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
float values[320];
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV
return result;
}
void setup(void) {
Serial.begin(9600);
tft.reset();
delay(10);
tft.begin(0x9341);
uint16_t identifier = tft.readID();
tft.fillScreen(BLACK);
tft.setRotation(1);
drawAxes();
for (int i = 0; i < 300;i+=2) {
values[i] = random(230);
}
for (int i = 0; i < 300;i+=2) {
drawBar(i, values[i]);
}
}
void loop() {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
// if you're sharing pins, you'll need to fix the directions of the touchscreen pins!
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > 10 ) {
Serial.print("X = ");
Serial.print(p.x);
Serial.print("\tY = ");
Serial.print(p.y);
Serial.print("\tPressure = ");
Serial.println(p.z);
// turn from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);
p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);
Serial.print("p.y:"); // this code will help you get the y and x numbers for the touchscreen
Serial.print(p.y);
Serial.print(" p.x:");
Serial.println(p.x);
tft.drawPixel(p.x, p.y, WHITE);
}
}
#define posx 10
#define posy 10
#define lenx 240
#define leny 320
void drawAxes(){
tft.drawLine(posx, posy, posx, 240 - posy , BLUE);
tft.drawLine(posx, 240 - posy, leny, 240 - posy, RED);
for (int x = posx; x < lenx;x+=25) {
tft.drawLine(0, 240 - x, posx, 240 - x, WHITE);
// Serial.println(x);
}
for (int y = posy; y < leny; y+=25) {
tft.drawLine(y, 240 - posy, y, 240, RED);
}
tft.setCursor(20, 10);
tft.print("Y");
tft.setCursor(leny - 20, lenx - 25);
tft.print("X");
}
void drawBar(int pos, float value) {
tft.drawLine(pos + posx + 1, 229, pos + posx + 1, 240 - (int) value, GREEN);
}