This commit is contained in:
Joseph Bryant 2024-04-22 13:43:14 -04:00
parent ab2a90ea5b
commit 8cacc107c9

19
lcd.c
View File

@ -23,6 +23,8 @@ char notesBuffer[NOTES_BUFFER_SIZE];
int serialIndex = 0; int serialIndex = 0;
int notesIndex = 0; int notesIndex = 0;
volatile int buttonState = 0; // Holds the state of all buttons volatile int buttonState = 0; // Holds the state of all buttons
unsigned char songBuffer[1024];
int count = 0;
void void
usart_init(void) usart_init(void)
@ -167,17 +169,18 @@ ISR(PCINT1_vect) {
void displayNotes() { void displayNotes() {
char circularBuffer[16]; char circularBuffer[16];
static int bufferIndex = 0; static int bufferIndex = 0;
lcd_clear(); lcd_clear();
lcd_gotoxy(6, 2); lcd_gotoxy(6, 2);
lcd_print("PLAYING"); lcd_print("PLAYING");
_delay_ms(1000); _delay_ms(1000);
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
while (buttonState == 4) { for(int k = 0; k < count) {
char randomValue = getNote(); unsigned char randomValue = songBuffer[k];
if (bufferIndex == 16) { if (bufferIndex == 16) {
// Remove the first value and shift other values down // Remove the first value and shift other values down
for (int i = 0; i < 16 - 1; i++) { for (int i = 0; i < 16 - 1; i++) {
circularBuffer[i] = circularBuffer[i + 1]; circularBuffer[i] = circularBuffer[i + 1];
@ -199,8 +202,9 @@ void displayNotes() {
lcd_print("PLAYING"); lcd_print("PLAYING");
} }
//_delay_ms(1000); _delay_ms(500);
} }
buttonState = 0;
bufferIndex = 0; bufferIndex = 0;
lcd_clear(); lcd_clear();
} }
@ -216,7 +220,10 @@ void displaySerialData() {
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
while (buttonState == 5) { while (buttonState == 5) {
char randomValue = getNote(); unsigned char randomValue = getNote();
count = 0;
songBuffer[count] = randomValue;
count++;
if (bufferIndex == 16) { if (bufferIndex == 16) {
// Remove the first value and shift other values down // Remove the first value and shift other values down
@ -257,7 +264,7 @@ void displayPiano() {
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
while (buttonState == 0) { while (buttonState == 0) {
char randomValue = getNote(); unsigned char randomValue = getNote();
if (bufferIndex == 16) { if (bufferIndex == 16) {
// Remove the first value and shift other values down // Remove the first value and shift other values down