/* Hard mode:⁣ you select the duration of the light being on and off while the program is running by entering it in the serial monitor. Write a code that takes the data from the serial monitor and delays by that amount of time. */ int D; //delay void setup() { pinMode(LED_BUILTIN,OUTPUT); // initialize digital pin LED_BUILTIN as an output. Serial.begin(9600); // Exchanges messages with the serial moniter D=0; } void loop() { Serial.println("Enter the LED duration"); // Prints the sentence to the serial moniter and creates a new line every time the sentence is written while (Serial.available() == 0){ //the default value in recived from the serial moniter is 0. this code is used to not do anything while nothing is written in the serial moniter. } D = Serial.parseFloat(); //reads the floating value entered in the serial moniter D=D*1000; // mutiplies the values by 1000 to convert from second to milliseconds if (D>0){ // when D is greater then 0, light up the LED for the number of seconds writen in the serial moniter digitalWrite(LED_BUILTIN,HIGH); delay (D); digitalWrite(LED_BUILTIN,LOW); delay(2000); } }