bargraph24.ino 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /***************************************************
  2. This is a library for our I2C LED Backpacks
  3. Designed specifically to work with the Adafruit LED 24 Bargraph Backpack
  4. ----> http://www.adafruit.com/products/721
  5. These displays use I2C to communicate, 2 pins are required to
  6. interface. There are multiple selectable I2C addresses. For backpacks
  7. with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  8. with 3 Address Select pins: 0x70 thru 0x77
  9. Adafruit invests time and resources providing this open source code,
  10. please support Adafruit and open-source hardware by purchasing
  11. products from Adafruit!
  12. Written by Limor Fried/Ladyada for Adafruit Industries.
  13. BSD license, all text above must be included in any redistribution
  14. ****************************************************/
  15. #include <Wire.h>
  16. #include <Adafruit_GFX.h>
  17. #include "Adafruit_LEDBackpack.h"
  18. Adafruit_24bargraph bar = Adafruit_24bargraph();
  19. void setup() {
  20. Serial.begin(9600);
  21. Serial.println("HT16K33 Bi-Color Bargraph test");
  22. bar.begin(0x70); // pass in the address
  23. for (uint8_t b=0; b<24; b++ ){
  24. if ((b % 3) == 0) bar.setBar(b, LED_RED);
  25. if ((b % 3) == 1) bar.setBar(b, LED_YELLOW);
  26. if ((b % 3) == 2) bar.setBar(b, LED_GREEN);
  27. }
  28. bar.writeDisplay();
  29. delay(2000);
  30. }
  31. void loop() {
  32. for (uint8_t b=0; b<24; b++) {
  33. bar.setBar(b, LED_RED);
  34. bar.writeDisplay();
  35. delay(50);
  36. bar.setBar(b, LED_OFF);
  37. bar.writeDisplay();
  38. }
  39. for (uint8_t b=0; b<24; b++) {
  40. bar.setBar(b, LED_GREEN);
  41. bar.writeDisplay();
  42. delay(50);
  43. bar.setBar(b, LED_OFF);
  44. bar.writeDisplay();
  45. }
  46. for (uint8_t b=0; b<24; b++) {
  47. bar.setBar(23-b, LED_YELLOW);
  48. bar.writeDisplay();
  49. delay(50);
  50. bar.setBar(23-b, LED_OFF);
  51. bar.writeDisplay();
  52. }
  53. }