Saturday, August 5, 2017

Blink a Digit


Blink a Digit

This is an example of conditional looping (iteration). In this activity a for statement is used to blink the LED the number of times specified by the global variable called digit. The for statement uses a variable x to loop a digit number of times. As long as the for statement is true it will continue to loop but once x becomes greater than digit the loop condition tests false and looping stops. Since the for statement is contained in the loop function the process repeats again and again each time after a 1 second delay.

Hookup for Blink a Digit


--------------------------- Copy Code Below

int digit = 7; //global, integer variable (seen in every function)
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{    
    for(int x = 1; x <= digit; x++)
    {
    digitalWrite(13, HIGH);
    delay(200);
    digitalWrite(13, LOW);
    delay(200);
    }
delay(1000);
}

------------------------ End of Code

Going Further:: 

1) Blink out the value of a sensor.

No comments:

Post a Comment