Review and Practice

Self-check

  • In this activity, you:
    • played with scripts and the write_analog() method to control the brightness of an LED assigned to a specific pin and
    • used loops with these scripts.
  • Were you able to calculate the appropriate values for write_analog() to get the desired brightness?
  • Were you able to use for...n in range() to adjust how the LED performed?  

Questions

  1. What frequency does the write_analog() method set for the light blink?
  2. A change in the high time for each light blink will appear to the eye as a change in what?
  3. What is the range for how long the light stays on using the write_analog() method?
  4. What values are needed in  a for...in range() loop to make it count values down?

Exercises

  1. To reduce the brightness of the light by ⅛, you need to change the argument of pin14.write_analog(1023) to what value?
  2. Calculate the necessary value for the write_analog()argument for 50% brightness.
  3. Calculate the necessary value for the write_analog() argument for 3/4th  brightness.
  4. Insert the necessary values in the following loop to make it count down by a step of 2 from 100 through 2. for n in range ( ).
  5. Write a for...in range() statement that will gradually increase the brightness of the LED to half its maximum value.

Project

  • Some sleep alarms increase in brightness to gently wake you and then try again if it doesn’t work. Alter the speed of the change and pauses in brightness to create this effect.