This program will count from 50 in increments of 10 every
250 milliseconds until it reaches 590 and then it will decrease
in increments of 5 every 100 milliseconds until it reaches 50.
When the counter is greater than 450, it will turn an LED on.
**************************************************************/
int counter = 50; // declares "counter" to have a value of 50
int LEDpin = 13; // LED is in pin 13
void setup()
{
pinMode(LEDpin, OUTPUT); //declares output for the built-in LED in pin 13
Serial.begin(9600); //starts the serial monitor
delay(10); //gives serial monitor time to attach all necessary code
Serial.println(""); //allows every printed line to be in same column
}
void loop()
{
counter = 50; //sets counter back to 50
while(counter < 590) //declares a condition that when the "counter" is less than 590 it will perform what's in the loop
{
if(counter > 450) // when the counter is greater than 450, it will turn the LED on
digitalWrite(LEDpin, HIGH); //turns LED on
else
digitalWrite(LEDpin, LOW); //turns LED off
Serial.print("The current value is "); //prints what is in quotes in the serial monitor
Serial.println(counter); //prints the value of "counter" in serial monitor on same line as previously printed line
delay(250); // prints the lines being printed every 250 milliseconds
counter+=10; // increments counter by 10
}
while (counter > 50)
{
if(counter > 450)
digitalWrite(LEDpin, HIGH);
else
digitalWrite(LEDpin, LOW);
Serial.print("The current value is ");
Serial.println(counter);
delay(100);
counter-=5;
}
}