int red_LED1 = 2; // This defines the pin number for the first LED
int red_LED2 = 3; // This defines the pin number for the second LED
int red_LED3 = 4; // This defines the pin number for the third LED
int red_LED4 = 5; // This defines the pin number for the fourth LED
int red_LED5 = 6; // This defines the pin number for the fifth LED
int DToff = 1000; // This sets the duration the LEDs is off by 1 second
int DTon = 2500; // This sets the duration the LEDs is on by 2.5 seconds
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // This initializes serial communication
pinMode(red_LED1, OUTPUT); // This sets the red_LED1 as an output
pinMode(red_LED2, OUTPUT); // This sets the red_LED2 as an output
pinMode(red_LED3, OUTPUT); // This sets the red_LED3 as an output
pinMode(red_LED4, OUTPUT); // This sets the red_LED4 as an output
pinMode(red_LED5, OUTPUT); // This sets the red_LED5 as an output
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Enter a value between 0 to 100"); // This prints the message and display the instruction to the user
while (Serial.available()==0){} // Pauses the program
int i; // this defines the variable to store user input
i = Serial.parseInt(); // reads the user input value
digitalWrite(red_LED1, LOW); // turns the first LED off
digitalWrite(red_LED2, LOW); // turns the second LED off
digitalWrite(red_LED3, LOW); // turns the third LED off
digitalWrite(red_LED4, LOW); // turns the fourth LED off
digitalWrite(red_LED5, LOW); // turns the fifth LED off
delay(DToff); // This turns the LEDs off for 1 second
// Level 1 -- User inputs a number from 0 - 20
if (i >= 0 && i <= 20){ // sets the range for the input value at level 1
Serial.println("This value is at level 1"); // Prints the category of the users input value onto the serial monitor
digitalWrite(red_LED1, HIGH); // Turns the red_LED1 on
delay(DTon); // adds a delay to the LED when turned on by about 2.5 seconds
digitalWrite(red_LED1, LOW); // Turns the red_LED1 off
delay(DToff); // adds a delay to the LED when turned off by 1 second
}else if (i<0) { // a given condition that rejects negative integers from being registered in the program
Serial.println("this value cannot be categorized"); // Prints the message onto the serial monitor
}
// Level 2 -- User inputs a number from 21 - 40
if (i >= 21 && i <= 40){ // sets the range for the input value at level 2
Serial.println("This value is at level 2"); // Prints the category of the users input value onto the serial monitor
digitalWrite(red_LED1, HIGH); // Turns the red_LED1 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
delay(400); // adds a delay to the LED when turned off by about 0.4 seconds
digitalWrite(red_LED2, HIGH); // Turns the red_LED2 on
delay(DTon); // adds a delay to the LED when turned on by about 2.5 seconds
digitalWrite(red_LED1, LOW); // Turns the red_LED1 off
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
delay(DToff); // adds a delay to the LED when turned on by about 1 second
}
// Level 3 -- User inputs a number from 41 - 60
if (i >= 41 && i <= 60){ // sets the range for the input value at level 3
Serial.println("This value is at level 3"); // Prints the category of the users input value onto the serial monitor
digitalWrite(red_LED1, HIGH); // Turns the red_LED1 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
delay(400); // adds a delay to the LED when turned off by about 0.4 seconds
digitalWrite(red_LED2, HIGH); // Turns the red_LED2 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
delay(300); // adds a delay to the LED when turned off by about 0.3 seconds
digitalWrite(red_LED3, HIGH); // Turns the red_LED3 on
delay(DTon); // adds a delay to the LED when turned on by about 2.5 seconds
digitalWrite(red_LED1, LOW); // Turns the red_LED1 off
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
delay(DToff); // adds a delay to the LED when turned on by about 1 second
}
// Level 4 -- User inputs a number from 61 - 80
if (i >= 61 && i <= 80){ // sets the range for the input value at level 4
Serial.println("This value is at level 4"); // Prints the category of the users input value onto the serial monitor
digitalWrite(red_LED1, HIGH); // Turns the red_LED1 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
delay(400); // adds a delay to the LED when turned off by about 0.4 seconds
digitalWrite(red_LED2, HIGH); // Turns the red_LED2 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
delay(300); // adds a delay to the LED when turned off by about 0.3 seconds
digitalWrite(red_LED3, HIGH); // Turns the red_LED3 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED4, LOW); // Turns the red_LED4 off
delay(200); // adds a delay to the LED when turned off by about 0.2 seconds
digitalWrite(red_LED4, HIGH); // Turns the red_LED4 on
delay(DTon); // adds a delay to the LED when turned on by about 2.5 seconds
digitalWrite(red_LED1, LOW); // Turns the red_LED1 off
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
digitalWrite(red_LED4, LOW); // Turns the red_LED4 off
delay(DToff); // adds a delay to the LED when turned on by about 1 second
}
// Level 5 -- User inputs a number from 81 - 100
if (i >= 81 && i <= 100){ // sets the range for the input value at level 5
Serial.println("This value is at level 5"); // Prints the category of the users input value onto the serial monitor
digitalWrite(red_LED1, HIGH); // Turns the red_LED1 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
delay(400); // adds a delay to the LED when turned off by about 0.4 seconds
digitalWrite(red_LED2, HIGH); // Turns the red_LED2 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
delay(300); // adds a delay to the LED when turned off by about 0.3 seconds
digitalWrite(red_LED3, HIGH); // Turns the red_LED3 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED4, LOW); // Turns the red_LED4 off
delay(200); // adds a delay to the LED when turned off by about 0.2 seconds
digitalWrite(red_LED4, HIGH); // Turns the red_LED4 on
delay(500); // adds a delay to the LED when turned on by about 0.5 seconds
digitalWrite(red_LED5, LOW); // Turns the red_LED5 off
delay(100); // adds a delay to the LED when turned off by about 100 milliseconds
digitalWrite(red_LED5, HIGH); // Turns the red_LED5 on
delay(DTon); // adds a delay to the LED when turned on by about 2.5 seconds
digitalWrite(red_LED1, LOW); // Turns the red_LED1 off
digitalWrite(red_LED2, LOW); // Turns the red_LED2 off
digitalWrite(red_LED3, LOW); // Turns the red_LED3 off
digitalWrite(red_LED4, LOW); // Turns the red_LED4 off
digitalWrite(red_LED5, LOW); // Turns the red_LED5 off
delay(DToff); // adds a delay to the LED when turned on by about 1 second
} else if(i > 100){
Serial.println("This value surpasses the assigned limit, please in");
}
// Clear any remaining data in the serial buffer
while (Serial.available() > 0) {
Serial.read();
}
}