Fully functional lcd!!!

This commit is contained in:
Joseph Bryant 2024-04-21 22:18:49 -04:00
parent a07dcfff94
commit 859b9f7781

56
lcd.c
View File

@ -132,7 +132,7 @@ void setup() {
ISR(PCINT1_vect) { ISR(PCINT1_vect) {
// Update button state when any pin changes state // 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 (PINC & (1 << i)) {
if(buttonState == 0) if(buttonState == 0)
buttonState = i; buttonState = i;
@ -148,8 +148,8 @@ void displayNotes() {
static int bufferIndex = 0; static int bufferIndex = 0;
lcd_clear(); lcd_clear();
lcd_gotoxy(1, 1); lcd_gotoxy(6, 2);
lcd_print("Play"); lcd_print("PLAY");
_delay_ms(1000); _delay_ms(1000);
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
@ -165,14 +165,14 @@ void displayNotes() {
circularBuffer[16 - 1] = randomValue; circularBuffer[16 - 1] = randomValue;
} else { } else {
// Add the new value to the buffer // Add the new value to the buffer
circularBuffer[bufferIndex++] = randomValue; circularBuffer[bufferIndex] = randomValue;
bufferIndex++;
} }
lcd_clear(); lcd_clear();
lcd_gotoxy(1, 1); for (int i = 0; i <= bufferIndex - 1; i++) {
for (int i = 0; i < bufferIndex; i++) { char singleChar[2] = {circularBuffer[i], '\0'};
char singleChar[2] = {circularBuffer[bufferIndex - i], '\0'}; lcd_gotoxy(17-bufferIndex+i ,1);
lcd_gotoxy(16 - i, 1);
lcd_print(singleChar); // Print the single character lcd_print(singleChar); // Print the single character
} }
@ -188,8 +188,8 @@ void displaySerialData() {
char circularBuffer[16]; char circularBuffer[16];
static int bufferIndex = 0; static int bufferIndex = 0;
lcd_clear(); lcd_clear();
lcd_gotoxy(1, 1); lcd_gotoxy(3, 2);
lcd_print("Record"); lcd_print("RECORD");
_delay_ms(1000); _delay_ms(1000);
lcd_clear(); lcd_clear();
_delay_ms(1000); _delay_ms(1000);
@ -205,16 +205,17 @@ void displaySerialData() {
circularBuffer[16 - 1] = randomValue; circularBuffer[16 - 1] = randomValue;
} else { } else {
// Add the new value to the buffer // Add the new value to the buffer
circularBuffer[bufferIndex++] = randomValue; circularBuffer[bufferIndex] = randomValue;
bufferIndex++;
} }
lcd_clear(); lcd_clear();
lcd_gotoxy(1,1); lcd_gotoxy(1,1);
for (int i = (bufferIndex > 16) ? bufferIndex - 16 : 0; i < bufferIndex; i++) { for (int i = 0; i <= bufferIndex-1; i++) {
char singleChar[2] = {circularBuffer[i], '\0'}; char singleChar[2] = {circularBuffer[bufferIndex- 1 - i], '\0'};
lcd_print(singleChar); // Print the single character lcd_print(singleChar); // Print the single character
} }
_delay_ms(1000); _delay_ms(1000);
} }
bufferIndex = 0; bufferIndex = 0;
@ -223,10 +224,8 @@ void displaySerialData() {
//******************************************************* //*******************************************************
int main(void) { int main(void) {
lcd_init();
lcd_init(); lcd_init();
lcd_hideCursor(); lcd_hideCursor();
setup(); setup();
lcd_clear(); lcd_clear();
while (1) { while (1) {
@ -236,23 +235,12 @@ int main(void) {
} else if (buttonState == 4) { } else if (buttonState == 4) {
displayNotes(); displayNotes();
} }
else {
lcd_gotoxy(6,2);
lcd_print("PIANO");
_delay_ms(1000);
}
} }
return 0; 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;*/
} }