Solutions

Questions

  1. Answer: 50 Hz
  2. Answer: Brightness
  3. Answer: 0 - 1024
  4. Answer: A start, stop, and (negative) step value.

Exercises

  1. Answer: change pin14.write_analog(1023) to pin14.write_analog(128)
  2. Answer: 1024 x 0.5 = 512
  3. Answer. 1024 x 0.75 = 768
  4. Answer: for n in range(100, 1, -2)
  5. Answer: for brightness in range(512)   Note: the variable name is up to the student.

Project

Solution:

from microbit import*

while True:
    for brightness in range(0,1023,10):
        sleep(500)
        pin14.write_analog(brightness)
                sleep(1000)