//define Global variables
const int LEDpin = 11; //set LED pin
int time_delay = 0;
int LEDstate = LOW;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.setTimeout(10);
pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, LOW);
Serial.println("Enter a value for blink frequency between 100 and 1000");
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0){
int data = Serial.parseInt();
if ((data >= 100) && (data <= 1000)){
time_delay = data;
}
}
/*
The reason why your code didn't work for the first example is because the first if statement doens't check whether or not the
vlaue is actually valid for the logic argument. It just prints the value if it is a valid integer size.
You needed to compare the variable the number you inputted instead as this is an actual value you
can do the logic arguments for as seen here
*/
if (LEDstate == LOW){
LEDstate = HIGH;
}
else{
LEDstate = LOW;
}
digitalWrite(LEDpin,LEDstate);
delay(time_delay);
}
/*
digitalWrite(LEDpin, HIGH)
delay(time_delay);
digitalWrite(LEDpin, LOW);
delay(time_delay);
This is good, howver, it doen't allow for the change of the delay inbetween the blinking.
The code has to finish forst before it changes
*/