-
Notifications
You must be signed in to change notification settings - Fork 0
/
05_UNIR_LCD_menu_Ultimate_Version.ino
237 lines (209 loc) · 7.62 KB
/
05_UNIR_LCD_menu_Ultimate_Version.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* Project:
05 UNIR - LCD menu Ultimate Version
Link: https://www.tinkercad.com/things/gL5unE1WIcH-copy-of-05-unir-lcd-menu-ultimate-version
Objective:
This project explains how to create a three-level menu and control an RGB LED :).
It was developed during the N.A.V.E TECH UNIR Samsung Eletrônica da Amazônia LTDA
In Porto Velho - RO - Brazil, Course from November 2023 to April 2024.
The project was supervised by Professor Dr. Ciro José Egoavil Montero
(https://www.linkedin.com/in/ciro-j-egoavil-210b7a44/?originalSubdomain=br),
an Associate Professor III in Electrical Engineering at the Federal University of Rondônia (UNIR).
homePage : (https://navetech.unir.br/) EDITAL Nº 01/2023/NAVE-Tech-RO/UNIR
(https://ciroegoavil.unir.br/homepage) Engenharia Elétrica da Fundação Universidade Federal de Rondônia (UNIR):
Authors: MARQUES, Ana P.; RIBEIRO, J.Antônio; OLIVEIRA, Gilberto Jr.
Hardware: Development Boards:
Arduino UNO: Microcontroller board based on the ATmega328P (datasheet)
Software: Tinkercad
Tinkercad is a free, easy-to-use app for 3D design, electronics, and coding.
Connections:
The LCD is connected to the microcontroller as follows:
Arduino UNO Rev.3 board:
Microcontroller LCD
=============== ===
D4 DB4
D5 DB5
D6 DB6
D7 DB7
D3 E
D2 R/S
GND RW
The RGB's Star is connected to the microcontroller as follows:
Arduino UNO Rev.3 board:
Microcontroller LCD
=============== ===
~D9 RGB (red)
~D10 RGB (green)
~D11 RGB (blue)
Date: 6 Dez 2023
*/
#include <LiquidCrystal.h>
#define B1 A1
#define B2 A2
#define B3 A3
#define B4 A4
#define redPin 9 // Replace with your actual pin numbers
#define greenPin 11 // Replace with your actual pin numbers
#define bluePin 10 // Replace with your actual pin numbers
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Set the correct pins for your LCD
int m_state_level_one = 1;
int m_state_level_two = 1;
int state_selected = 0;
int submenu = 0;
int x = 0, y = 0;
void setup() {
pinMode(B1, INPUT);
pinMode(B2, INPUT);
pinMode(B3, INPUT);
pinMode(B4, INPUT);
pinMode(redPin, OUTPUT); // Pin definitions for LEDs
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
// splash init 5 seconds delay
lcd.begin(16, 2); // Adjust the number of columns and rows on your LCD
lcd.print("Navetec Group 03");
lcd.setCursor(0, 1);
lcd.print("****************");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" ANA P. MARQUES");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" GILBERTO JR");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("ANTONIO RIBEIRO");
delay(2000);
lcd.clear();
lcd.noCursor();
lcd.setCursor(0, 0);
lcd.print(">MANUAL [ENTER]");
lcd.setCursor(0, 1);
lcd.print(" AUTOMAT ");
}
void loop() {
int ENTER_MENU = digitalRead(B2);
int SELECT_MENU = digitalRead(B1);
int RETURN_MAIN_MENU = digitalRead(B3);
int STOP = digitalRead(B4);
if (SELECT_MENU == HIGH && submenu == 0) {
switch (m_state_level_one) {
case 1:
lcd.setCursor(0, 0);
lcd.print(">");
lcd.setCursor(9, 0);
lcd.print("[ENTER]");
m_state_level_one = 2;
state_selected = 1;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(9, 1);
lcd.print(" ");
break;
case 2:
lcd.setCursor(0, 1);
lcd.print(">");
lcd.setCursor(9, 1);
lcd.print("[ENTER]");
m_state_level_one = 1;
state_selected = 2;
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(9, 0);
lcd.print(" ");
break;
}
}
if (ENTER_MENU == HIGH) {
switch (state_selected) {
case 1:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" MANUAL");
lcd.setCursor(9, 0);
lcd.print("> RED");
lcd.setCursor(9, 1);
lcd.print(" GREEN");
submenu = 1;
break;
case 2:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" AUTOMAT");
submenu = 1;
for (int i = 0; i < 4; i++) {
lcd.setCursor(9, 0);
lcd.print("> RED");
digitalWrite(redPin, HIGH); // Turn on RED LED
delay(1000);
digitalWrite(redPin, LOW); // Turn off RED LED
lcd.setCursor(9, 0);
lcd.print("> GREEN");
digitalWrite(greenPin, HIGH); // Turn on GREEN LED
delay(1000);
digitalWrite(greenPin, LOW); // Turn off GREEN LED
lcd.setCursor(9, 0);
lcd.print("> BLUE");
digitalWrite(bluePin, HIGH); // Turn on BLUE LED
delay(1000);
digitalWrite(bluePin, LOW); // Turn off BLUE LED
}
break;
}
}
if (STOP == HIGH) {
if (m_state_level_two == 1){digitalWrite(greenPin, LOW);}
if (m_state_level_two == 3){digitalWrite(bluePin, LOW);}
if (m_state_level_two == 2){digitalWrite(redPin, LOW);}
}
if (SELECT_MENU == HIGH && submenu == 1) {
switch (m_state_level_two) {
case 1:
if (m_state_level_two == 1){digitalWrite(redPin, LOW);}
lcd.setCursor(9, 1);
lcd.print("> GREEN");
m_state_level_two = 3;
lcd.setCursor(9, 0);
lcd.print(" RED");
digitalWrite(greenPin, HIGH); // Turn on RED LED
//delay(1000);
break;
case 2:
if (m_state_level_two == 2){digitalWrite(bluePin, LOW);}
m_state_level_two = 1;
lcd.setCursor(9, 0);
lcd.print("> RED");
lcd.setCursor(9, 1);
lcd.print(" GREEN");
digitalWrite(redPin, HIGH); // Turn on RED LED
//delay(1000);
break;
case 3:
if (m_state_level_two == 3){digitalWrite(greenPin, LOW);}
m_state_level_two = 2;
lcd.setCursor(9, 0);
lcd.print(" GREEN");
lcd.setCursor(9, 1);
lcd.print("> BLUE");
digitalWrite(bluePin, HIGH); // Turn on RED LED
//delay(1000);
break;
}
}
if (RETURN_MAIN_MENU == HIGH && submenu == 1) {
// Action: Return to main menu
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">MANUAL [ENTER]");
lcd.setCursor(0, 1);
lcd.print(" AUTOMAT ");
submenu = 0; // Set submenu back to 0 to indicate it is in the main menu
m_state_level_one = 1; // Reset the state of the first menu level
m_state_level_two = 1; // Reset the state of the second menu level
state_selected = 0; // Reset the selected state
}
delay(250); // Necessary to treat debounce
}