commit 6a28f45c514cdacf47d466f14b0bc69abccd064f
parent 77e29b942cf316fb809efcbed2c2e9245f6ed820
Author: Joseph Bryant <jbryant0653@floridapoly.edu>
Date: Sun, 21 Apr 2024 20:46:16 -0400
Trying to fix scrolling
Diffstat:
| M | lcd.c | | | 70 | +++++++++++++++++++++++++++++++++++++++++++++++----------------------- |
1 file changed, 47 insertions(+), 23 deletions(-)
diff --git a/lcd.c b/lcd.c
@@ -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,30 +170,55 @@ void displaySerialData() {
lcd_clear();
lcd_gotoxy(1, 1);
- for (int i = 0; i < 16; i++) {
- char singleChar[2] = {circularBuffer[i], '\0'};
+ 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 displayNotes() {
+void displaySerialData() {
+ char circularBuffer[16];
+ static int bufferIndex = 0;
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
+ 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;
}
- _delay_ms(1000); // Adjust delay as needed
+
+ 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();
}
//*******************************************************
@@ -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;