#include <Arduino.h>
// ------------------------------------------------------------
// Copyright © 2026/2027 Dr. Mohammad Alja'afreh. All rights reserved.
// PSUT IoT Engineering Learning Platform
// ------------------------------------------------------------
// ---- Store the pin number of the LED.
int ledPin = 13;                    // on-board LED pin
 
void setup() {                      // runs once at start
  // Configure the LED pin as an output.
  pinMode(ledPin, OUTPUT);          // LED pin = output
 
  // Start serial communication at 9600 bits per second.
  Serial.begin(9600);               // same baud rate as the Pi
}
 
void loop() {                       // repeats forever
  // ---- Check whether data has arrived from the Raspberry Pi.
  if (Serial.available() > 0) {
    // Read one incoming character.
    char received = Serial.read();  // one byte, e.g. 'H'
 
    // If the command is H, turn the LED on.
    if (received == 'H') {
      digitalWrite(ledPin, HIGH);   // LED on
    }
    // If the command is L, turn the LED off.
    else if (received == 'L') {
      digitalWrite(ledPin, LOW);    // LED off
    }
  }
}
