add notes circular buffer to piano lcd

This commit is contained in:
Vineet K 2024-04-21 23:32:44 -04:00 committed by Shokara Kou
parent f61f9355da
commit 20e98aeb95

50
lcd.c
View File

@ -46,9 +46,6 @@ getNote(void)
// convert to capital hex
else if (c >= 0xa && c <= 0xf)
c = c - 0xa + 'A';
// shift to rest of alphabet
else if (c >= 0x10)
c = c - 0x10 + 'G';
return c;
}
@ -209,7 +206,6 @@ void displayNotes() {
}
void displaySerialData() {
char circularBuffer[16];
static int bufferIndex = 0;
@ -251,10 +247,52 @@ void displaySerialData() {
lcd_clear();
}
void displayPiano() {
char circularBuffer[16];
static int bufferIndex = 0;
lcd_clear();
lcd_gotoxy(6, 2);
lcd_print("PIANO");
_delay_ms(1000);
lcd_clear();
_delay_ms(1000);
while (buttonState == 0) {
char randomValue = getNote();
if (bufferIndex == 16) {
// Remove the first value and shift other values down
for (int i = 0; i < 16 - 1; i++) {
circularBuffer[i] = circularBuffer[i + 1];
}
// Add the new value at the end
circularBuffer[16 - 1] = randomValue;
} else {
// Add the new value to the buffer
circularBuffer[bufferIndex] = randomValue;
bufferIndex++;
}
lcd_clear();
lcd_gotoxy(1,1);
for (int i = 0; i <= bufferIndex-1; i++) {
char singleChar[2] = {circularBuffer[bufferIndex- 1 - i], '\0'};
lcd_gotoxy(i+1,1);
lcd_print(singleChar); // Print the single character
lcd_gotoxy(6, 2);
lcd_print("PIANO");
}
_delay_ms(1000);
}
bufferIndex = 0;
lcd_clear();
}
//*******************************************************
int main(void) {
lcd_init();
lcd_hideCursor();
usart_init();
setup();
lcd_clear();
while (1) {
@ -266,9 +304,7 @@ int main(void) {
displayNotes();
}
else {
lcd_gotoxy(6,2);
lcd_print("PIANO");
_delay_ms(1000);
displayPiano();
}
}
return 0;