Functions Challenge

Hardware

Write a function named blink that takes 2 parameters :

  • pin number
  • milliseconds delay between state changes

Use the function in a program with 2 LEDs:

  • The onboard LED should blink every x milliseconds where x is defined by the value of potentiometer
  • The external LED on socket should blink every 2 * x milliseconds

Fade function

Write a function named fade that takes 1 parameter : pin number. It makes and LED fade in 5 steps. Steps duration is defined by the potentiometer. The maximum value is 500 milliseconds. The minimum value is 30 milliseconds.

Use the function in a program with 2 LEDs:

  • The onboard LED.
  • The external LED.

Alternating Blink and Fade

Write a program that reuses the previous functions blink and fade.

  • Initially,
    • the onboard LED should blink
    • the LED on socket should fade
  • When the button is pressed:
    • the onboard LED should fade
    • the LED on socket should blink
  • Another button press will make us go back to the initial state

Delay vs Blinking Durations

Change the previous programs to ensure that the blinking durations are correct.

Hint