summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVineet K <git@vineetk.net>2024-04-21 23:32:44 -0400
committerShokara Kou <kou@13f0.net>2024-04-21 23:32:44 -0400
commit20e98aeb95e4bfb36bd13f275f34d738eb945968 (patch)
treedcda67af8cce30bd3ea5f35e38719e519aed0042
parentf61f9355daeb1ff28716f40087d7380c0b219713 (diff)
add notes circular buffer to piano lcd
-rw-r--r--lcd.c50
1 files changed, 43 insertions, 7 deletions
diff --git a/lcd.c b/lcd.c
index 5501d86..d60cb1e 100644
--- a/lcd.c
+++ b/lcd.c
@@ -46,9 +46,6 @@ getNote(void)
46 // convert to capital hex 46 // convert to capital hex
47 else if (c >= 0xa && c <= 0xf) 47 else if (c >= 0xa && c <= 0xf)
48 c = c - 0xa + 'A'; 48 c = c - 0xa + 'A';
49 // shift to rest of alphabet
50 else if (c >= 0x10)
51 c = c - 0x10 + 'G';
52 49
53 return c; 50 return c;
54} 51}
@@ -209,7 +206,6 @@ void displayNotes() {
209} 206}
210 207
211 208
212
213void displaySerialData() { 209void displaySerialData() {
214 char circularBuffer[16]; 210 char circularBuffer[16];
215 static int bufferIndex = 0; 211 static int bufferIndex = 0;
@@ -251,10 +247,52 @@ void displaySerialData() {
251 lcd_clear(); 247 lcd_clear();
252} 248}
253 249
250void displayPiano() {
251 char circularBuffer[16];
252 static int bufferIndex = 0;
253 lcd_clear();
254 lcd_gotoxy(6, 2);
255 lcd_print("PIANO");
256 _delay_ms(1000);
257 lcd_clear();
258 _delay_ms(1000);
259 while (buttonState == 0) {
260 char randomValue = getNote();
261
262 if (bufferIndex == 16) {
263 // Remove the first value and shift other values down
264 for (int i = 0; i < 16 - 1; i++) {
265 circularBuffer[i] = circularBuffer[i + 1];
266 }
267 // Add the new value at the end
268 circularBuffer[16 - 1] = randomValue;
269 } else {
270 // Add the new value to the buffer
271 circularBuffer[bufferIndex] = randomValue;
272 bufferIndex++;
273 }
274
275 lcd_clear();
276 lcd_gotoxy(1,1);
277 for (int i = 0; i <= bufferIndex-1; i++) {
278 char singleChar[2] = {circularBuffer[bufferIndex- 1 - i], '\0'};
279 lcd_gotoxy(i+1,1);
280 lcd_print(singleChar); // Print the single character
281 lcd_gotoxy(6, 2);
282 lcd_print("PIANO");
283 }
284
285 _delay_ms(1000);
286 }
287 bufferIndex = 0;
288 lcd_clear();
289}
290
254//******************************************************* 291//*******************************************************
255int main(void) { 292int main(void) {
256 lcd_init(); 293 lcd_init();
257 lcd_hideCursor(); 294 lcd_hideCursor();
295 usart_init();
258 setup(); 296 setup();
259 lcd_clear(); 297 lcd_clear();
260 while (1) { 298 while (1) {
@@ -266,9 +304,7 @@ int main(void) {
266 displayNotes(); 304 displayNotes();
267 } 305 }
268 else { 306 else {
269 lcd_gotoxy(6,2); 307 displayPiano();
270 lcd_print("PIANO");
271 _delay_ms(1000);
272 } 308 }
273 } 309 }
274 return 0; 310 return 0;