mirror of
https://codeberg.org/eel4746_piano/avr_piano.git
synced 2024-11-22 01:00:29 -05:00
read lcd values from usart instead of random
This commit is contained in:
parent
4644a4b0ae
commit
f61f9355da
38
lcd.c
38
lcd.c
@ -23,6 +23,35 @@ char notesBuffer[NOTES_BUFFER_SIZE];
|
||||
int serialIndex = 0;
|
||||
int notesIndex = 0;
|
||||
volatile int buttonState = 0; // Holds the state of all buttons
|
||||
|
||||
void
|
||||
usart_init(void)
|
||||
{
|
||||
// 9600 bps, RX enabled
|
||||
UBRR0 = 103;
|
||||
UCSR0B = 1 << RXEN0;
|
||||
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
|
||||
}
|
||||
|
||||
char
|
||||
getNote(void)
|
||||
{
|
||||
while (!(UCSR0A & (1 << RXC0)));
|
||||
|
||||
unsigned char c = UDR0;
|
||||
|
||||
// convert 0-9 to ascii character
|
||||
if (c <= 9)
|
||||
c += '0';
|
||||
// convert to capital hex
|
||||
else if (c >= 0xa && c <= 0xf)
|
||||
c = c - 0xa + 'A';
|
||||
// shift to rest of alphabet
|
||||
else if (c >= 0x10)
|
||||
c = c - 0x10 + 'G';
|
||||
|
||||
return c;
|
||||
}
|
||||
//
|
||||
void lcd_putValue(unsigned char val)
|
||||
{
|
||||
@ -111,11 +140,6 @@ char getSerialData() {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
char getNote() {
|
||||
// Read notes data and return it
|
||||
return ' ';
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// Initialize Serial communication
|
||||
// Initialize LCD
|
||||
@ -154,7 +178,7 @@ void displayNotes() {
|
||||
lcd_clear();
|
||||
_delay_ms(1000);
|
||||
while (buttonState == 4) {
|
||||
char randomValue = '0' + (rand() % 10);
|
||||
char randomValue = getNote();
|
||||
|
||||
if (bufferIndex == 16) {
|
||||
// Remove the first value and shift other values down
|
||||
@ -196,7 +220,7 @@ void displaySerialData() {
|
||||
lcd_clear();
|
||||
_delay_ms(1000);
|
||||
while (buttonState == 5) {
|
||||
char randomValue = '0' + (rand() % 10);
|
||||
char randomValue = getNote();
|
||||
|
||||
if (bufferIndex == 16) {
|
||||
// Remove the first value and shift other values down
|
||||
|
Loading…
Reference in New Issue
Block a user