Now that the Blink subroutine function is complete, we can go back to completing the loop section of our program. Looking at the program requirements, we can pick out three key points:
1 - If the blink count is less than 10, we need to blink the LED at 100 millisecond intervals:
if (Count < 10) {
Blink(100);
}
2 - But, if the blink count is greater than 10 but less than 20, the LED must blink at 500 milliseconds:
else if (Count < 20) {
Blink(500);
}
3 - Once a total of 20 blinks have been achieved, turn the LED off completely:
else {
digitalWrite(LED, HIGH);
}
We have now completed the code and you can use the source code to test on you own boards. You can see how we have used the subroutine, conditional statements and the MFS 4x7 segment display. This function is great for code efficiency and allows us to perform an operation with a shorter program, rather than repeating instruction sets.