#include "Arduino.h"
#define LED_PIN 2 // Define the GPIO pin number for the LED
void setup() {
Serial.begin(115200); // Initialize the default UART0 for communication
pinMode(LED_PIN, OUTPUT); // Set the LED pin as an output
}
void loop() {
// Check if data is available to read from UART0
if (Serial.available()) {
String receivedString = Serial.readStringUntil('\n'); // Read the incoming string until newline character
receivedString.trim(); // Remove any leading/trailing whitespace
// For debugging, print the received string to the Serial Monitor
Serial.println("Received: " + receivedString);
// Check the received string and control the LED accordingly
if (receivedString == "l1=1") {
digitalWrite(LED_PIN, HIGH); // Turn LED ON
Serial.println("LED ON"); // Echo back for confirmation
} else if (receivedString == "l1=0") {
digitalWrite(LED_PIN, LOW); // Turn LED OFF
Serial.println("LED OFF"); // Echo back for confirmation
}
}
// Add a small delay to give some time back to the CPU
delay(10);
}