summaryrefslogtreecommitdiff
path: root/lcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcd.c')
-rw-r--r--lcd.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/lcd.c b/lcd.c
index 2257196..d859320 100644
--- a/lcd.c
+++ b/lcd.c
@@ -23,6 +23,7 @@ char notesBuffer[NOTES_BUFFER_SIZE];
23int serialIndex = 0; 23int serialIndex = 0;
24int notesIndex = 0; 24int notesIndex = 0;
25volatile int buttonState = 0; // Holds the state of all buttons 25volatile int buttonState = 0; // Holds the state of all buttons
26 //
26void lcd_putValue(unsigned char val) 27void lcd_putValue(unsigned char val)
27{ 28{
28 LCD_DPRT &= 0x0F; 29 LCD_DPRT &= 0x0F;
@@ -133,20 +134,26 @@ ISR(PCINT1_vect) {
133 // Update button state when any pin changes state 134 // Update button state when any pin changes state
134 for (unsigned char i = 0; i <= 5; i++) { 135 for (unsigned char i = 0; i <= 5; i++) {
135 if (PINC & (1 << i)) { 136 if (PINC & (1 << i)) {
136 buttonState = i; 137 if(buttonState == 0)
138 buttonState = i;
139 else
140 buttonState = 0;
137 break; 141 break;
138 } 142 }
139 } 143 }
140} 144}
141 145
142void displaySerialData() { 146void displayNotes() {
143 char circularBuffer[16]; 147 char circularBuffer[16];
144 static int bufferIndex = 0; 148 static int bufferIndex = 0;
145 149
146 lcd_clear(); 150 lcd_clear();
147 lcd_gotoxy(1, 1); 151 lcd_gotoxy(1, 1);
148 lcd_print("KindaGood"); 152 lcd_print("Play");
149 while ((PINC & _BV(5)) == 0) { 153 _delay_ms(1000);
154 lcd_clear();
155 _delay_ms(1000);
156 while (buttonState == 4) {
150 char randomValue = '0' + (rand() % 10); 157 char randomValue = '0' + (rand() % 10);
151 158
152 if (bufferIndex == 16) { 159 if (bufferIndex == 16) {
@@ -163,30 +170,55 @@ void displaySerialData() {
163 170
164 lcd_clear(); 171 lcd_clear();
165 lcd_gotoxy(1, 1); 172 lcd_gotoxy(1, 1);
166 for (int i = 0; i < 16; i++) { 173 for (int i = 0; i < bufferIndex; i++) {
167 char singleChar[2] = {circularBuffer[i], '\0'}; 174 char singleChar[2] = {circularBuffer[bufferIndex - i], '\0'};
175 lcd_gotoxy(16 - i, 1);
168 lcd_print(singleChar); // Print the single character 176 lcd_print(singleChar); // Print the single character
169 } 177 }
170 178
171 _delay_ms(1000); 179 _delay_ms(1000);
172 } 180 }
181 bufferIndex = 0;
173 lcd_clear(); 182 lcd_clear();
174} 183}
175 184
176 185
177 186
178void displayNotes() { 187void displaySerialData() {
188 char circularBuffer[16];
189 static int bufferIndex = 0;
179 lcd_clear(); 190 lcd_clear();
180 lcd_gotoxy(1, 1); 191 lcd_gotoxy(1, 1);
181 while (buttonState == 4) { 192 lcd_print("Record");
182 char newNote = getNote(); 193 _delay_ms(1000);
183 if (newNote != '\0') { 194 lcd_clear();
184 // Add new note to the right side of line 1 of the LCD 195 _delay_ms(1000);
185 // Push existing notes to the left 196 while (buttonState == 5) {
186 // Display on LCD 197 char randomValue = '0' + (rand() % 10);
198
199 if (bufferIndex == 16) {
200 // Remove the first value and shift other values down
201 for (int i = 0; i < 16 - 1; i++) {
202 circularBuffer[i] = circularBuffer[i + 1];
203 }
204 // Add the new value at the end
205 circularBuffer[16 - 1] = randomValue;
206 } else {
207 // Add the new value to the buffer
208 circularBuffer[bufferIndex++] = randomValue;
187 } 209 }
188 _delay_ms(1000); // Adjust delay as needed 210
211 lcd_clear();
212 lcd_gotoxy(1,1);
213 for (int i = (bufferIndex > 16) ? bufferIndex - 16 : 0; i < bufferIndex; i++) {
214 char singleChar[2] = {circularBuffer[i], '\0'};
215 lcd_print(singleChar); // Print the single character
216 }
217
218 _delay_ms(1000);
189 } 219 }
220 bufferIndex = 0;
221 lcd_clear();
190} 222}
191 223
192//******************************************************* 224//*******************************************************
@@ -200,18 +232,10 @@ int main(void) {
200 while (1) { 232 while (1) {
201 // Check button state and perform actions accordingly 233 // Check button state and perform actions accordingly
202 if (buttonState == 5) { 234 if (buttonState == 5) {
203 lcd_gotoxy(1,1);
204 lcd_print("good");
205 displaySerialData(); 235 displaySerialData();
206 buttonState = 0;
207 236
208 } else if (buttonState == 4) { 237 } else if (buttonState == 4) {
209 lcd_clear(); 238 displayNotes();
210 lcd_gotoxy(1,2);
211 lcd_print("Button A4 Works");
212 _delay_ms(100);
213 buttonState = 0;
214 //displayNotes();
215 } 239 }
216 } 240 }
217 return 0; 241 return 0;