const int serialBufferLength = 17; // Define the length of the serial buffer
char serialBuffer[serialBufferLength]; // Create a character array to store the serial data
unsigned long previousMillis = 0; // Store the previous timestamp
bool dataReady = false; // Flag to indicate if data is ready to be processed
void setup() {
Serial.begin(57600); // Initialize serial communication at 9600 baud
Serial.println("Hello Arduino\n");
}
void loop() {
unsigned long currentMillis = millis(); // Get the current timestamp
/*if (currentMillis - previousMillis >= 600) { // Check if 60 seconds have passed
previousMillis = currentMillis; // Update the previous timestamp
dataReady = false; // Reset the data ready flag
}*/
if (Serial.available() > 0) { // Check if serial data is available
char c = Serial.read(); // Read a single character
if (c == '#') { // Check if the character is the start of the data
Serial.println("# found\n");
int index = 0; // Initialize the buffer index
while (index < serialBufferLength - 1 && Serial.available() > 0) {
char a = Serial.read();
Serial.print(a);
serialBuffer[index++] = a; // Read and store the remaining data
}
//serialBuffer[index] = '\0'; // Null-terminate the string
dataReady = true; // Set the data ready flag
}
}
if (dataReady) { // Check if data is ready to be processed
Serial.println(serialBuffer); // Print the received data
Serial.println("ready\n");dataReady = false; // Reset the data ready flag
}
}