We wrote a basic library to help you work with the bi-color bargraph backpack. The library is written for the Arduino and will work with any Arduino as it just uses the I2C pins. The code is very portable and can be easily adapted to any I2C-capable micro.
Wiring to the bargraph is really easy
- Connect SCL to the I2C clock - on Arduino UNO thats Analog #5, on the Leonardo its Digital #3, on the Mega its digital #21
- Connect SDA to the I2C data - on Arduino UNO thats Analog #4, on the Leonardo its Digital #2, on the Mega its digital #20
- Connect GND to common ground
- Connect VCC to power - 5V is best but 3V also seems to work for 3V microcontrollers.
Next, download the Adafruit LED Backpack library and the Adafruit GFX library from the Arduino library manager.
Open up the Arduino library manager:
Search for the Adafruit LED Backpack library and install it
Search for the Adafruit GFX library and install it
If using an earlier version of the Arduino IDE (prior to 1.8.10), also locate and install Adafruit_BusIO (newer versions will install this dependency automatically).
Once you've restarted you should be able to select the File->Examples->Adafruit_LEDBackpack->bargraph24 example sketch. Upload it to your Arduino as usual. You should see a basic test program that tests all the LEDs with different colors.
We also have a great tutorial on Arduino library installation at:
Adafruit_24bargraph bar = Adafruit_24bargraph();you can name it whatever you want, not just bar
Then initialize it with
bar.begin(0x70); // pass in the addressYou can init with any address from 0x70 to 0x77, just make sure you solder in the matching solder jumpers!
Finally, write to the bargraph with
bar.setBar(lednumber, ledcolor);Where lednumber is 0 thru 23. ledcolor can be LED_RED, LED_YELLOW, LED_GREEN or LED_OFF
The drawing routines only change the display memory kept by the Arduino. Don't forget to call bar.writeDisplay() after drawing to 'save' the memory out to the matrix via I2C.
There are also a few small routines that are special to the matrix:
- setBrightness(brightness)- will let you change the overall brightness of the entire display. 0 is least bright, 15 is brightest and is what is initialized by the display when you start
- blinkRate(rate) - You can blink the entire display. 0 is no blinking. 1, 2 or 3 is for display blinking.