Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
922 B
1
Indexable
Never
#include <avr/io.h>
#include <util/delay.h>
#include <LCD.h>

#define BUFFER_SIZE 100 // Define buffer size for input string

int main (void) {
    LCD lcd;
    lcd.init();
    char buffer[BUFFER_SIZE];
    int bufferIndex = 0;

    // Initialize UART here as in your code

    while (1) {
        if(checkbit(UCSRA, bitn(RXC))) { // If data received
            char receivedData = UDR; // Read data
            
            if (receivedData == '\n') { // If newline, process command
                buffer[bufferIndex] = '\0'; // Null-terminate the string
                // Process the buffer here (compare with categories)
                // Reset bufferIndex after processing
                bufferIndex = 0;
            } else if (bufferIndex < BUFFER_SIZE - 1) { // Prevent buffer overflow
                buffer[bufferIndex++] = receivedData; // Store in buffer and increment index
            }
        }
    }
}
Leave a Comment