Exercise: Soft Blink¶
Objective¶
Use conventional programming structures such as loops, local variables, and functions to implement software PWM using the on-board LED.
Steps and observations¶
Load and run the SoftBlink1 sketch.
Read through the explanations in the comments. Try varying the parameters.
Load and run the SoftBlink2 sketch.
Read through the explanations in the comments. Try modifiying the pattern.
Comments¶
This exercise demonstrates how defining functions can improve clarity and maintainability of the code by reducing redundancy. Another framing is that function definitions constitute a new application-specific language. By creating a new abstraction of the low-level ramp pattern, it becomes to simpler to express the solution to the higher-order problem of generating the complex blink pattern over time.
Challenges¶
Add a sensor acquisition process to read an external input and modulate the performance.
Arduino Code¶
Documentation: SoftBlink1 Arduino Sketch
Documentation: SoftBlink2 Arduino Sketch
Sketch Folder: SoftBlink1
Sketch Folder: SoftBlink2