7 Segment displays

class electronics.devices.sevensegment.SevenSegmentGPIO(segments)

Class for driving a single character 7 segment display connected to GPIO pins

This class only works with 8-pin 7 segment displays (not multiplexed in any way). Connect a gpio pin to every segment pin of the display and connect to common anode or cathode to vcc or gnd.

Initialize this class with the pins in this order:

  1. top segment
  2. top left segment
  3. top right segment
  4. middle segment
  5. bottom left segment
  6. bottom right segment
  7. bottom segment
>>> # Connect to a MCP23017 port expander because we need 7 GPIOs
>>> expander = MCP23017I2C(gw)
>>> display_pins = expander.get_pins()[0:7]
>>> # Create a SevenSegmentGPIO instance for the display
>>> display = SevenSegmentGPIO(display_pins)
>>> # Display a number
>>> display.write(6)
>>> # Letters are also supported
>>> display.write('h')

Display a single character on the display

Parameters:char (str or int) – Character to display