From 77e29b942cf316fb809efcbed2c2e9245f6ed820 Mon Sep 17 00:00:00 2001 From: Joseph Bryant Date: Sun, 21 Apr 2024 17:46:59 -0400 Subject: [PATCH] Made button A5 work and shifting random characters --- lcd.c | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/lcd.c b/lcd.c index d5da485..2257196 100644 --- a/lcd.c +++ b/lcd.c @@ -2,6 +2,7 @@ #define F_CPU 16000000UL // THE CPU FREQUENCY #include //delay header #include //interrupt header +#include #define LCD_DPRT PORTD //LCD DATA PORT #define LCD_DDDR DDRD //LCD DATA DDR @@ -139,19 +140,41 @@ ISR(PCINT1_vect) { } void displaySerialData() { + char circularBuffer[16]; + static int bufferIndex = 0; + lcd_clear(); lcd_gotoxy(1, 1); - while (!(buttonState == 5)) { - char newData = getSerialData(); - if (newData != '\0') { - // Add new data to the left side of line 1 of the LCD - // Push existing data to the right - // Display on LCD + lcd_print("KindaGood"); + while ((PINC & _BV(5)) == 0) { + char randomValue = '0' + (rand() % 10); + + 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; } - _delay_ms(100); // Adjust delay as needed + + lcd_clear(); + lcd_gotoxy(1, 1); + for (int i = 0; i < 16; i++) { + char singleChar[2] = {circularBuffer[i], '\0'}; + lcd_print(singleChar); // Print the single character + } + + _delay_ms(1000); } + lcd_clear(); } + + void displayNotes() { lcd_clear(); lcd_gotoxy(1, 1); @@ -177,16 +200,17 @@ int main(void) { while (1) { // Check button state and perform actions accordingly if (buttonState == 5) { - lcd_clear(); - lcd_gotoxy(1,1); - lcd_print("Button A5 Works"); - _delay_ms(100); - //displaySerialData(); + lcd_gotoxy(1,1); + lcd_print("good"); + displaySerialData(); + buttonState = 0; + } else if (buttonState == 4) { lcd_clear(); lcd_gotoxy(1,2); lcd_print("Button A4 Works"); _delay_ms(100); + buttonState = 0; //displayNotes(); } }