const int ledPins[] = {10, 11, 12, 13};
const int numLeds = 4;
bool runBlinking = false;
void setup() {
Serial.begin(9600);
Serial.println("r - run s - stop ");
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n');
command.trim();
if (command == "r") {
runBlinking = true;
} else if (command == "s") {
runBlinking = false;
turnOffLeds();
}
}
if (runBlinking) {
blinkLeds();
}
}
void blinkLeds() {
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], HIGH); // Turn the LED on
delay(1000);
digitalWrite(ledPins[i], LOW); // Turn the LED off
}
delay(500); // Wait for 500 milliseconds
}
void turnOffLeds() {
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], LOW); // Turn off all LEDs
}
}