Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

BBC micro:bit MicroPython MY9221

A micro:bit MicroPython library for 10 segment LED bar graph modules using the MY9221 LED driver.

For example, the Grove - LED Bar module

demo

Installation

  • Install MicroPython for micro:bit by either compiling from source or using one of my precompiled firmwares
  • Install ufs to upload .py scripts
  • Copy my9221.py and one of the example main.py scripts to the micro:bit
  • Reset to run main.py on boot.

Examples

frommicrobitimport*frommy9221importMY9221ledbar=MY9221(di=pin1, dcki=pin2, reverse=False)
# all LEDS on, full brightnessledbar.level(10)
# four LEDS on, half brightnessledbar.level(4, 0x0F)
# first and last LED onledbar.bits(0b1000000001)
ledbar.bits(0x201)
ledbar.bits(513)
# alternating LEDsledbar.bits(0b0101010101)
ledbar.bits(0b1010101010)
# fade out LEDsbuf=bytearray([0,1,3,7,15,31,63,127,255,255])
ledbar.bytes(buf)
# reverse orientation, first LED is greenledbar.reverse(True)
ledbar.level(1)
# normal orientation, first LED is redledbar.reverse(False)
ledbar.level(1)

For more detailed examples, see /examples.

Methods

Get or set the orientation. The red LED normally position 1, and when reversed is position 10. Once orientation has been set, all other methods respect the order.

reverse(val=None)

Illuminate a number of LEDs at a specific brightness. A value of 5 would light half of the display.

level(val, brightness=255)

Illuminate LEDs, one bit per LED at a specific brightness. Value can be 0-1023.

bits(val, brightness=255)

Use a bytearray, one byte per LED, to specify individual brightness for each LED.

bytes(buf)

Parts

Connections

micro:bitGrove LED Bar
Pin 1DI (yellow)
Pin 2DCKI (white)
3V3VCC (red)
GNDGND (black)

An edge connector breakout board comes in handy here.

You're welcome to change the data and clock pins to something else - just update MY9221(di=pin1, dcki=pin2) in your main.py

Links

License

Licensed under the MIT License.

About

MicroPython for micro:bit library for 10 segment LED bar graph modules using the MY9221 LED driver

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages