#define LED_PIN 14 // define the LED pin 13 for Ardoino
int LEDState = LOW; // pair this with
int delayTime = 2000; // global variable to store blink delay interval
void setup() {
Serial.begin(115200); // initialise serial communication
Serial.setTimeout(10); // reduce from the default 1000 to 10ms
while (!Serial) {
continue; // wait for serial port to connect
}
pinMode(LED_PIN, OUTPUT); // set pin connected to LED as output
digitalWrite(LED_PIN, LOW); // match LEDState initialisation
Serial.println("Enter a blink delay between 100 and 4000 milliseconds.");
}
void loop() {
// check for data on the serial buffer
if (Serial.available() > 0) {
int input = Serial.parseInt();
// validate input
if ( (input >= 10) && (input <= 4000) ) {
// change the delayTime used in the blink loop
delayTime = input;
Serial.print("Received valid delay time: ");
Serial.println(input);
} else {
Serial.print("Received invalid delay time: ");
Serial.println(input);
}
Serial.println();
Serial.println("Enter a new blink delay between 100 and 4000 milliseconds.");
}
// Toggle the LED
if (LEDState == LOW) {
LEDState = HIGH;
} else {
LEDState = LOW;
}
digitalWrite(LED_PIN, LEDState);
delay(delayTime); // wait for blink delay interval
}