-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLarge_text_scroling_LCD.ino
129 lines (102 loc) · 3.47 KB
/
Large_text_scroling_LCD.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
LCD Text Scroling with SD card module
This example shows how get info out of your sd card and display it
on a 16*2 LCD display. This works with large texts. It can also be used
to display a string instead of getting the text from the SD card.
To display only in one line, please remove all "Top Line" comments and
remove the "2 *" from the main for cicle.
As it is, the code will display text on the bottom line from the right
to the left and then jump to the top line, from the right to the left again.
The circuit:
SD card and LCD display:
-- LCD Display
** GND <---> GND
** VCC <---> 5V
** SDA <---> A4 on Arduino Nano Every
** SCL <---> A5 Arduino Nano Every
-- SD card module
** GND <---> GND
** MISO <---> D12 Arduino Nano Every
** CLK <---> D13 Arduino Nano Every
** MOSI <---> D11 Arduino Nano Every
** CS <---> D4 Arduino Nano Every
** VCC <---> 3.3V
*
created 30 November 2021
by Octávio Jardim and Francisco Nunes
*/
//----------------------------------
#include <LiquidCrystal_I2C.h>
#include <SD.h>
//----------------------------------
LiquidCrystal_I2C lcd(0x27, 16, 2);
File card;
const int RIGHT_LIMIT = 16;
const int LEFT_LIMIT = 0;
const int SPEED = 500; // 0.5 seconds
const int SCREEN_SIZE = 16;
const int SD_CARD = 4; //CS PIN
char buf[SCREEN_SIZE + 1]; // Top Line
char buf2[SCREEN_SIZE + 1];
int k = 0;
//----------------------------------
void (*resetFunc) () = 0; // reset fuction
//----------------------------------
void setup() {
while (!SD.begin(SD_CARD)) {} // waits for the SD card module to connect
buf[SCREEN_SIZE] = NULL; // Top Line
buf2[SCREEN_SIZE] = NULL;
lcd.init(); //initialize lcd screen
lcd.backlight(); // turn on the backlight
lcd.clear(); // clear the lcd screen
card = SD.open("dummy.txt"); // open the file for reading
}
//----------------------------------
void loop() {
if (card) {
while (card.available() and k < SCREEN_SIZE) { //execute while file is available
buf[k] = ' '; // Top Line
buf2[k] = ' ';
k++;
}
while (card.available()) {
lcd.setCursor(0, 0); // Top Line
lcd.print(displayFormattedText(buf)); // Top Line
lcd.setCursor(0, 1);
lcd.print(displayFormattedText(buf2));
char letter = card.read(); //read next character from file
delay(SPEED);
if (letter == '\n' || letter == '\r' ) { // remove end of line character
letter = ' ';
}
slideLeft(letter);
}
card.close(); //close file
for (int i = 0; i < 2 * SCREEN_SIZE; i++) { //if only one line, remove "2 *" from for cicle
slideLeft(' ');
lcd.setCursor(0, 0); // Top Line
lcd.print(displayFormattedText(buf)); // Top Line
lcd.setCursor(0, 1);
lcd.print(displayFormattedText(buf2));
delay(SPEED);
}
} else {
// if the file didn't open
}
resetFunc(); //call reset
}
//----------------------------------
String displayFormattedText(String StrDisplay) {
return StrDisplay.substring(LEFT_LIMIT, RIGHT_LIMIT);
}
//----------------------------------
void slideLeft(char nextChar) {
char c = buf2[0];
for (int i = 1; i < SCREEN_SIZE; i++) {
buf[i - 1] = buf[i]; // Top Line
buf2[i - 1] = buf2[i];
}
buf[SCREEN_SIZE - 1] = c; // Top Line
buf2[SCREEN_SIZE - 1] = nextChar;
}
//----------------------------------