Skip to content

Latest commit

 

History

History
101 lines (71 loc) · 2.44 KB

single-led.md

File metadata and controls

101 lines (71 loc) · 2.44 KB
title layout meta-description share author about cats simple-description acknowledgements date date-updated
Light an external LED on the microbit bit
text-width-sidebar
Use electronics and breadboard to light a single LED with the micro:bit.
true
jez
Light a Single External LED.
external
LEDs
Teaser image by Adafruit (CC-BY).
2016-12-23 10:20:00 UTC
2016-12-23 10:20:00 UTC

It's possible to use the external pins on the micro:bit to control external LEDs.

{:.ui .dividing .header}

Electronics

Electric current can only flow one way through a light emitting diode (LED). It must flow through its anode (+) and out its cathode (-) to light.

The anode has a longer leg and often has a bend in it.

Single LED{:.ui .image}

A 220Ω resistor is added to reduce the voltage; without it the LED would blow.

{% include box.html content="which-resistor" %}

{:.ui .dividing .header}

Code

Python MS Blocks

Flash a Single LED

{% highlight python %} from microbit import *

while True: pin0.write_digital(1) sleep(500) pin0.write_digital(0) sleep(500) {% endhighlight %}

Fade an LED

{% highlight python %} from microbit import *

fade_amount = 5 # How much to change brightness each iteration speed = 10 # speed brightness changes brightness = 0

while True: brightness = brightness + fade_amount if (brightness <= 0) or (brightness >= 1023): fade_amount = -fade_amount else: pin0.write_analog(brightness) sleep(speed) {% endhighlight %}

Creates a lot of flickering in Python; not quite sure yet.

#### Flash a Single LED

Experiment

  • Remove the resistor; what happens?
  • Reverse the polarity of the LED; what happens?
  • Make the LED flash when the button is pushed.