mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 09:10:30 -05:00
Made button A5 work and shifting random characters
This commit is contained in:
parent
0c484fcae0
commit
77e29b942c
48
lcd.c
48
lcd.c
@ -2,6 +2,7 @@
|
|||||||
#define F_CPU 16000000UL // THE CPU FREQUENCY
|
#define F_CPU 16000000UL // THE CPU FREQUENCY
|
||||||
#include <util/delay.h> //delay header
|
#include <util/delay.h> //delay header
|
||||||
#include <avr/interrupt.h> //interrupt header
|
#include <avr/interrupt.h> //interrupt header
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define LCD_DPRT PORTD //LCD DATA PORT
|
#define LCD_DPRT PORTD //LCD DATA PORT
|
||||||
#define LCD_DDDR DDRD //LCD DATA DDR
|
#define LCD_DDDR DDRD //LCD DATA DDR
|
||||||
@ -139,19 +140,41 @@ ISR(PCINT1_vect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void displaySerialData() {
|
void displaySerialData() {
|
||||||
|
char circularBuffer[16];
|
||||||
|
static int bufferIndex = 0;
|
||||||
|
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_gotoxy(1, 1);
|
lcd_gotoxy(1, 1);
|
||||||
while (!(buttonState == 5)) {
|
lcd_print("KindaGood");
|
||||||
char newData = getSerialData();
|
while ((PINC & _BV(5)) == 0) {
|
||||||
if (newData != '\0') {
|
char randomValue = '0' + (rand() % 10);
|
||||||
// Add new data to the left side of line 1 of the LCD
|
|
||||||
// Push existing data to the right
|
if (bufferIndex == 16) {
|
||||||
// Display on LCD
|
// 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() {
|
void displayNotes() {
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_gotoxy(1, 1);
|
lcd_gotoxy(1, 1);
|
||||||
@ -177,16 +200,17 @@ int main(void) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
// Check button state and perform actions accordingly
|
// Check button state and perform actions accordingly
|
||||||
if (buttonState == 5) {
|
if (buttonState == 5) {
|
||||||
lcd_clear();
|
lcd_gotoxy(1,1);
|
||||||
lcd_gotoxy(1,1);
|
lcd_print("good");
|
||||||
lcd_print("Button A5 Works");
|
displaySerialData();
|
||||||
_delay_ms(100);
|
buttonState = 0;
|
||||||
//displaySerialData();
|
|
||||||
} else if (buttonState == 4) {
|
} else if (buttonState == 4) {
|
||||||
lcd_clear();
|
lcd_clear();
|
||||||
lcd_gotoxy(1,2);
|
lcd_gotoxy(1,2);
|
||||||
lcd_print("Button A4 Works");
|
lcd_print("Button A4 Works");
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
|
buttonState = 0;
|
||||||
//displayNotes();
|
//displayNotes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user