![]() Here's where we will use an 'else' statement. Once 10 blinks have been achieved, we are required to turn the LED off completely. The Arduino will now loop within the 'if' condition until the counter reaches 10. We simply print the integer as a whole in the serial monitor without speech marks because we are displaying the global variable value. Once the blink number has been stored, the program requirements ask us to numerically display this in the serial monitor. This increments the value only by 1 after each blink. To increase the value of 'Count', we use a '++' instruction. Because this variable has been declared as an integer, we are able to modify its initial value throughout the code. This will blink the LED once, so we must record this blink to 'Count'. To blink the LED, we will simply digitally write the pin HIGH and LOW with a delay of 500 milliseconds. If the counter is less than 10, the program will not proceed and loop within the 'if' statement. The variable 'Count' is used within the condition because if the value of 'Count' is less than 10, we want the LED to blink. From the program requirements, we are told that after 10 LED blinks the LED must turn off completely. The first step we will take in to writing the main program will be to define the conditions of the 'if' statement. Once the global variables have been declared and the program has been setup, we can move on to the main coding loop. This is done in 'void setup' the same way as we had done in lesson 3. The value of this variable will be changing as the LED blinks, and therefore it is declared as an integer with an initial count value of 0.Īfter the global variables have been declared within the scope, we will be setting up the pin mode for the LED pin as an output and initialising the serial monitor at a baud rate of 9600 bits per second. We will also be declaring another variable which will be used to count the blinks. The data type of this variable will remain as a constant integer. In the global scope, we will be declaring a variable name for pin 13, which will be used as our LED pin. The requirements we will be working against in this program are:ġ) Blink an LED 10 times at half a second intervalsĢ) Each blink should be numerically displayed in the serial monitorĤ) After 10 blinks, the LED should turn off completely, until the Arduino is reset It is important to close these parenthesis off, to avoid syntax errors. Note: Curly parenthesis are used to contain the code for each conditional statement. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |