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

190
TFT_FONT/TFT_FONT.ino Executable file
View File

@@ -0,0 +1,190 @@
/*
Show all the fonts and demonstrate wrap function.
Only font sizes 1, 2, 4, 6 and 7 are implemented in the Adafruit_GFX_AS library.
*/
#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ILI9341_8bit_AS.h>// Hardware-specific library
#include <SPI.h>
#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
Adafruit_ILI9341_8bit_AS tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// ############### Add these lines #############
#ifdef LOAD_GLCD
#include "glcdfont.c"
#endif
#ifdef LOAD_FONT2
#include "Font16.h"
#endif
#ifdef LOAD_FONT4
#include "Font32.h"
#endif
#ifdef LOAD_FONT6
#include "Font64.h"
#endif
#ifdef LOAD_FONT7
#include "Font7s.h"
#endif
// 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
#define ORANGE 0xF400
// ##############################################
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
// tft.init();
tft.reset();
delay(10);
tft.begin(0x9341);
tft.setRotation(1);
}
void loop() {
tft.fillScreen(BLACK);
tft.setTextColor(GREEN, BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 1, 1);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 2, 1);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 4, 1);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" -.0123456789:amp", 0, 0, 6, 1);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" -.0123456789:", 0, 0, 7, 1);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 1, 2);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 2, 2);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 0, 0, 4, 2);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" -.012p3456789:amp", 0, 0, 6, 2);
delay(4000);
tft.fillScreen(BLACK);
wrapString(" -.0123456789:", 0, 0, 7, 2);
delay(4000);
}
// Add this function to your sketch, it will draw the character string
// on the display and wrap to next line if too long.
//
// dX and dY = top left plot coordinates
// font = font number
// text size is multiplier for size, normally 1
void wrapString(char *string, int dX, int dY, int font, int textsize)
{
int len = 0;
int hgt = 0;
char ascii;
int width = tft.width();
int height = tft.height();
while (*string)
{
ascii = *string;
#ifdef LOAD_GLCD
if (font == 1) {
len = 6 * textsize;
hgt = 8 * textsize;
}
#endif
#ifdef LOAD_FONT2
if (font == 2) {
len = (pgm_read_byte(widtbl_f16 + ascii - 32) + 1) * textsize;
hgt = 16 * textsize;
}
#endif
#ifdef LOAD_FONT4
if (font == 4) {
len = (pgm_read_byte(widtbl_f32 + ascii - 32) - 3) * textsize;
hgt = 24 * textsize;
}
#endif
#ifdef LOAD_FONT6
if (font == 6) {
len = (pgm_read_byte(widtbl_f64 + ascii - 32) - 3) * textsize;
hgt = 48 * textsize;
}
#endif
#ifdef LOAD_FONT7
if (font == 7) {
len = (pgm_read_byte(widtbl_f7s + ascii - 32) + 2) * textsize;
hgt = 52 * textsize;
}
#endif
if (dX + len > width) {
dX = 0; dY += hgt;
if (dY + hgt > height) dY = 0; // Wrap to top of screen but may not look good!
}
tft.setTextSize(textsize);
tft.drawChar(*string, dX, dY, font);
dX+=len;
*string++;
}
}