Trying to fix scrolling

This commit is contained in:
Joseph Bryant 2024-04-21 20:46:16 -04:00
parent 77e29b942c
commit 6a28f45c51

84
lcd.c
View File

@ -23,6 +23,7 @@ char notesBuffer[NOTES_BUFFER_SIZE];
int serialIndex = 0;
int notesIndex = 0;
volatile int buttonState = 0; // Holds the state of all buttons
//
void lcd_putValue(unsigned char val)
{
LCD_DPRT &= 0x0F;
@ -133,20 +134,26 @@ ISR(PCINT1_vect) {
// Update button state when any pin changes state
for (unsigned char i = 0; i <= 5; i++) {
if (PINC & (1 << i)) {
buttonState = i;
if(buttonState == 0)
buttonState = i;
else
buttonState = 0;
break;
}
}
}
void displaySerialData() {
void displayNotes() {
char circularBuffer[16];
static int bufferIndex = 0;
lcd_clear();
lcd_gotoxy(1, 1);
lcd_print("KindaGood");
while ((PINC & _BV(5)) == 0) {
lcd_print("Play");
_delay_ms(1000);
lcd_clear();
_delay_ms(1000);
while (buttonState == 4) {
char randomValue = '0' + (rand() % 10);
if (bufferIndex == 16) {
@ -163,32 +170,57 @@ void displaySerialData() {
lcd_clear();
lcd_gotoxy(1, 1);
for (int i = 0; i < 16; i++) {
for (int i = 0; i < bufferIndex; i++) {
char singleChar[2] = {circularBuffer[bufferIndex - i], '\0'};
lcd_gotoxy(16 - i, 1);
lcd_print(singleChar); // Print the single character
}
_delay_ms(1000);
}
bufferIndex = 0;
lcd_clear();
}
void displaySerialData() {
char circularBuffer[16];
static int bufferIndex = 0;
lcd_clear();
lcd_gotoxy(1, 1);
lcd_print("Record");
_delay_ms(1000);
lcd_clear();
_delay_ms(1000);
while (buttonState == 5) {
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;
}
lcd_clear();
lcd_gotoxy(1,1);
for (int i = (bufferIndex > 16) ? bufferIndex - 16 : 0; i < bufferIndex; i++) {
char singleChar[2] = {circularBuffer[i], '\0'};
lcd_print(singleChar); // Print the single character
}
_delay_ms(1000);
}
bufferIndex = 0;
lcd_clear();
}
void displayNotes() {
lcd_clear();
lcd_gotoxy(1, 1);
while (buttonState == 4) {
char newNote = getNote();
if (newNote != '\0') {
// Add new note to the right side of line 1 of the LCD
// Push existing notes to the left
// Display on LCD
}
_delay_ms(1000); // Adjust delay as needed
}
}
//*******************************************************
int main(void) {
lcd_init();
@ -200,18 +232,10 @@ int main(void) {
while (1) {
// Check button state and perform actions accordingly
if (buttonState == 5) {
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();
displayNotes();
}
}
return 0;