3
3
// then scroll smoothly
4
4
5
5
// Needs GLCD font
6
+ // adapted for 135x240 screen from TTGO T-Display
7
+
8
+ // Here https://github.com/Bodmer/TFT_eSPI/issues/493 the comment ghostoy solved the problem
6
9
7
10
/*
8
11
Make sure all the display driver and pin comnenctions are correct by
19
22
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
20
23
21
24
#define TEXT_HEIGHT 8 // Height of text to be printed and scrolled
22
- #define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
23
- #define TOP_FIXED_AREA 0 // Number of lines in top fixed area (lines counted from top of screen)
25
+ #define BOT_FIXED_AREA 40 // Number of lines in bottom fixed area (lines counted from bottom of screen)
26
+ #define TOP_FIXED_AREA 40 // Number of lines in top fixed area (lines counted from top of screen)
24
27
25
28
uint16_t yStart = TOP_FIXED_AREA;
26
- uint16_t yArea = 240 - TOP_FIXED_AREA - BOT_FIXED_AREA;
27
- uint16_t yDraw = 240 - BOT_FIXED_AREA - TEXT_HEIGHT;
29
+ uint16_t yArea = 320 - TOP_FIXED_AREA - BOT_FIXED_AREA;
30
+ uint16_t yDraw = 240 - TEXT_HEIGHT;
28
31
byte pos[42 ];
29
32
uint16_t xPos = 0 ;
30
33
@@ -38,46 +41,36 @@ void setup() {
38
41
}
39
42
40
43
void loop (void ) {
41
- // First fill the screen with random streaks of characters
42
- for (int j = 0 ; j < 400 ; j += TEXT_HEIGHT) {
44
+ // First fill the screen with random streaks of characters
45
+ for (int j = 0 ; j < 600 ; j += TEXT_HEIGHT) {
43
46
for (int i = 0 ; i < 40 ; i++) {
44
- // Rapid fade initially brightness values
45
- if (pos[i] > 20 )
46
- pos[i] -= 3 ;
47
- // Slow fade later
48
- if (pos[i] > 0 )
49
- pos[i] -= 1 ;
50
- // ~1 in 20 probability of a new character
51
- if ((random (20 ) == 1 ) && (j < 200 ))
52
- pos[i] = 63 ;
53
- // Set the green character brightness
54
- tft.setTextColor (pos[i] << 5 , TFT_BLACK);
55
- // Draw white character
56
- if (pos[i] == 63 )
57
- tft.setTextColor (TFT_WHITE, TFT_BLACK);
58
- // Draw the character
59
- xPos += tft.drawChar (random (32 , 128 ), xPos, yDraw, 1 );
47
+ if (pos[i] > 20 ) pos[i] -= 3 ; // Rapid fade initially brightness values
48
+ if (pos[i] > 0 ) pos[i] -= 1 ; // Slow fade later
49
+ if ((random (20 ) == 1 ) && (j<400 )) pos[i] = 63 ; // ~1 in 20 probability of a new character
50
+ tft.setTextColor (pos[i] << 5 , TFT_BLACK); // Set the green character brightness
51
+ if (pos[i] == 63 ) tft.setTextColor (TFT_WHITE, TFT_BLACK); // Draw white character
52
+ xPos += tft.drawChar (random (32 , 128 ), xPos, yDraw, 1 ); // Draw the character
60
53
}
61
- // Scroll, 14ms per pixel line
62
- yDraw = scroll_slow (TEXT_HEIGHT, 14 );
54
+ yDraw = scroll_slow (TEXT_HEIGHT, 14 ); // Scroll, 14ms per pixel line
63
55
xPos = 0 ;
64
56
}
65
57
58
+ // tft.setRotation(2);
59
+ // tft.setTextColor(63 << 5, ILI9341_BLACK);
60
+ // tft.drawCentreString("MATRIX",120,60,4);
61
+ // tft.setRotation(0);
62
+
66
63
// Now scroll smoothly forever
67
- while (1 ) {
68
- yield ();
69
- yDraw = scroll_slow (240 , 5 );
70
- } // Scroll 320 lines, 5ms per line
64
+ while (1 ) {yield (); yDraw = scroll_slow (320 ,5 ); }// Scroll 320 lines, 5ms per line
71
65
72
66
}
73
67
74
68
void setupScrollArea (uint16_t TFA, uint16_t BFA) {
75
- // Vertical scroll definition
76
- tft.writecommand (ST7789_VSCRDEF);
69
+ tft.writecommand (ST7789_VSCRDEF); // Vertical scroll definition
77
70
tft.writedata (TFA >> 8 );
78
71
tft.writedata (TFA);
79
- tft.writedata ((240 - TFA - BFA) >> 8 );
80
- tft.writedata (240 - TFA - BFA);
72
+ tft.writedata ((320 - TFA - BFA) >> 8 );
73
+ tft.writedata (320 - TFA - BFA);
81
74
tft.writedata (BFA >> 8 );
82
75
tft.writedata (BFA);
83
76
}
@@ -86,17 +79,15 @@ int scroll_slow(int lines, int wait) {
86
79
int yTemp = yStart;
87
80
for (int i = 0 ; i < lines; i++) {
88
81
yStart++;
89
- if (yStart == 240 - BOT_FIXED_AREA)
90
- yStart = TOP_FIXED_AREA;
82
+ if (yStart == 320 - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA;
91
83
scrollAddress (yStart);
92
84
delay (wait);
93
85
}
94
- return yTemp;
86
+ return yTemp - 40 ;
95
87
}
96
88
97
89
void scrollAddress (uint16_t VSP) {
98
- // Vertical scrolling start address
99
- tft.writecommand (0x37 ); // ILI9341_VSCRSADD);
90
+ tft.writecommand (0x37 ); // Vertical scrolling start address ILI9341_VSCRSADD
100
91
tft.writedata (VSP >> 8 );
101
92
tft.writedata (VSP);
102
93
}
0 commit comments