CircuitPython Code

The bicolor bar graph display is demonstrated in the script. This code will light up 3 bars in different colors and then loop through full color all on and all off modes. 

# SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
# SPDX-License-Identifier: MIT

# Basic example of using the Bi-color 24 segment bargraph display.
# This example and library is meant to work with Adafruit CircuitPython API.
# Author: Carter Nelson
# License: Public Domain

import time
import board
import busio

# Import the Bicolor24 driver from the HT16K33 module
from adafruit_ht16k33.bargraph import Bicolor24

# Create the I2C interface
i2c = busio.I2C(board.SCL, board.SDA)

# Create the LED bargraph class.
bc24 = Bicolor24(i2c)

# Set individual segments of bargraph
bc24[0] = bc24.LED_RED
bc24[1] = bc24.LED_GREEN
bc24[2] = bc24.LED_YELLOW


# Turn them all off

# Turn them on in a loop
for i in range(24):
    bc24[i] = bc24.LED_RED
    bc24[i] = bc24.LED_OFF


# Fill the entrire bargraph

Download and Run the Code

We can easily copy this code onto our Pi's home directory using the 'wget' command and then run it using the following commands.


This guide was first published on Aug 24, 2012. It was last updated on May 24, 2024.

This page (Bicolor Bar Graph 24) was last updated on May 24, 2024.

Text editor powered by tinymce.