2.4.3. Exercise: Soft Blink¶
2.4.3.1. Objective¶
Use conventional programming structures such as loops, local variables, and functions to implement software PWM using the on-board LED.
2.4.3.2. 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.
2.4.3.3. 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.
2.4.3.4. Challenges¶
- Add a sensor acquisition process to read an external input and modulate the performance.
2.4.3.5. Arduino Code¶
- Documentation: SoftBlink1 Arduino Sketch
- Documentation: SoftBlink2 Arduino Sketch
- Sketch Folder: SoftBlink1
- Sketch Folder: SoftBlink2