Made button A5 work and shifting random characters

This commit is contained in:
Joseph Bryant 2024-04-21 17:46:59 -04:00
parent 0c484fcae0
commit 77e29b942c

46
lcd.c
View File

@ -2,6 +2,7 @@
#define F_CPU 16000000UL // THE CPU FREQUENCY
#include <util/delay.h> //delay header
#include <avr/interrupt.h> //interrupt header
#include <stdlib.h>
#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];
}
_delay_ms(100); // Adjust delay as needed
// Add the new value at the end
circularBuffer[16 - 1] = randomValue;
} else {
// Add the new value to the buffer
circularBuffer[bufferIndex++] = randomValue;
}
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_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();
}
}