This lab consists in using a potentiometer to control three LEDs. According to the potentiometer value, a specific LED is turned on or off. The main loop reads the potentiometer through the ADC, switching more LEDs on as its value increases or switching more LEDs off as its value decreases.
Let's begin with a pseudo code (actual coding is up to you):
1. |
int main() { |
The pseudo-code is self-explaining: an infinite loop reading the ADC channel to which the potentiometer has been connected and a composed conditional to switch on/off the LEDs through the respective GPIO ports. The delay at the end of the loop is a good practice in terms of energy, since a tight loop, checking the potentiometer faster then it actually can vary would be useless. A well implemented delay could put the MCU in a low-power mode while keeping a timer counting.
For this lab, you'll need the following components: