C12 Embedded systems in MicroPython and C · Practice
Blink in MicroPython
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
An LED is on for 100 ms and off for 150 ms. At what frequency does it blink?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
On for 100 ms and off for 150 ms: what's the duty cycle?
Check
An LED should blink at 2 Hz with a 10% duty cycle. How long is it on in each period?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
A fixed-sleep loop also spends 2 ms on work each pass. How far behind is it after 100 passes?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A loop makes 50 hardware calls (40 µs each) and then sleeps 5 ms. How long does one pass take?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Blink the LED on P0: on for 200 ms, off for 100 ms, forever.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
Toggle P0 every 125 ms without drifting, even though each pass also reads P4 (a pull-up input) ten times.
MicroPython on the course's board: machine (Pin, PWM, ADC, DAC, UART, I2C, SPI, Timer, WDT) and time. Each call into the hardware takes about 40 µs. Tab indents; press Esc and then Tab to move on.
Check
An LED blinks at 2 Hz with a 10% duty cycle.
(a)
How long is it on each cycle?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
And off?
Check
A MicroPython loop makes 1 hardware call(s) of 40 µs, then sleeps 100 ms.
(a)
How long is each pass?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
After 8 hours, how far behind is a count of passes against one made with exactly 100 ms passes?
Check
Blink frequency for 20 ms on, 80 ms off?
Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.
Check
On-time for 4 Hz at 20% duty?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
Check
Drift after 500 passes with 1 ms of work?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C12