From 859b9f7781d2fc57cfbad02b6174761be8c9ce3f Mon Sep 17 00:00:00 2001 From: Joseph Bryant Date: Sun, 21 Apr 2024 22:18:49 -0400 Subject: [PATCH] Fully functional lcd!!! --- lcd.c | 56 ++++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/lcd.c b/lcd.c index d859320..3e18d80 100644 --- a/lcd.c +++ b/lcd.c @@ -132,7 +132,7 @@ void setup() { ISR(PCINT1_vect) { // Update button state when any pin changes state - for (unsigned char i = 0; i <= 5; i++) { + for (unsigned char i = 4; i <= 5; i++) { if (PINC & (1 << i)) { if(buttonState == 0) buttonState = i; @@ -148,8 +148,8 @@ void displayNotes() { static int bufferIndex = 0; lcd_clear(); - lcd_gotoxy(1, 1); - lcd_print("Play"); + lcd_gotoxy(6, 2); + lcd_print("PLAY"); _delay_ms(1000); lcd_clear(); _delay_ms(1000); @@ -165,14 +165,14 @@ void displayNotes() { circularBuffer[16 - 1] = randomValue; } else { // Add the new value to the buffer - circularBuffer[bufferIndex++] = randomValue; + circularBuffer[bufferIndex] = randomValue; + bufferIndex++; } lcd_clear(); - lcd_gotoxy(1, 1); - for (int i = 0; i < bufferIndex; i++) { - char singleChar[2] = {circularBuffer[bufferIndex - i], '\0'}; - lcd_gotoxy(16 - i, 1); + for (int i = 0; i <= bufferIndex - 1; i++) { + char singleChar[2] = {circularBuffer[i], '\0'}; + lcd_gotoxy(17-bufferIndex+i ,1); lcd_print(singleChar); // Print the single character } @@ -188,8 +188,8 @@ void displaySerialData() { char circularBuffer[16]; static int bufferIndex = 0; lcd_clear(); - lcd_gotoxy(1, 1); - lcd_print("Record"); + lcd_gotoxy(3, 2); + lcd_print("RECORD"); _delay_ms(1000); lcd_clear(); _delay_ms(1000); @@ -205,16 +205,17 @@ void displaySerialData() { circularBuffer[16 - 1] = randomValue; } else { // Add the new value to the buffer - circularBuffer[bufferIndex++] = randomValue; + circularBuffer[bufferIndex] = randomValue; + bufferIndex++; } - + lcd_clear(); lcd_gotoxy(1,1); - for (int i = (bufferIndex > 16) ? bufferIndex - 16 : 0; i < bufferIndex; i++) { - char singleChar[2] = {circularBuffer[i], '\0'}; + for (int i = 0; i <= bufferIndex-1; i++) { + char singleChar[2] = {circularBuffer[bufferIndex- 1 - i], '\0'}; lcd_print(singleChar); // Print the single character } - + _delay_ms(1000); } bufferIndex = 0; @@ -223,10 +224,8 @@ void displaySerialData() { //******************************************************* int main(void) { - lcd_init(); lcd_init(); lcd_hideCursor(); - setup(); lcd_clear(); while (1) { @@ -236,23 +235,12 @@ int main(void) { } else if (buttonState == 4) { displayNotes(); - } + } + else { + lcd_gotoxy(6,2); + lcd_print("PIANO"); + _delay_ms(1000); + } } return 0; - /*while (1) { - lcd_clear(); - lcd_gotoxy(1, 1); - lcd_print("Note 1:"); - lcd_gotoxy(1, 2); - lcd_print("one country"); - lcd_showCursor(); - _delay_ms(2500); - lcd_clear(); - lcd_gotoxy(1, 1); - lcd_print("and mankind its"); - lcd_gotoxy(1, 2); - lcd_print("citizens."); - _delay_ms(3500); - } - return 0;*/ }