๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Need help controlling 24 bar graph (1721)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Need help controlling 24 bar graph (1721)

by vader7071 on Tue Jan 23, 2018 3:59 pm

So I am working on a project, and I am using (3) 870 (8x8 matrix) and (1) 1721 (24 bar graph).

I have the 870's working. No worries there. But I need some help with the 1721. I have the example code. But that just looks like it either flashes all the LEDs or walks them one at the time.

I was wondering if there is a way I can send a 24 bit "word" to the board and control all the LEDs in one shot? My end run is to control all the LEDs in red only. No use for yellow or green. So they will either be on or off. I can see where the commands below do the work (b indicating which led to work on).
Code: Select all | TOGGLE FULL SIZE
bar.setBar(b, LED_RED);
bar.writeDisplay;


If possible, I'd like to be able to control the bar without having to write:
Code: Select all | TOGGLE FULL SIZE
bar.setBar(0 LED_[OFF or RED]);
bar.setBar(1 LED_[OFF or RED]);
.....
bar.setBar(23 LED_[OFF or RED]);
bar.writeDisplay;

delay(500);

bar.setBar(0 LED_[OFF or RED]);
bar.setBar(1 LED_[OFF or RED]);
.....
bar.setBar(23 LED_[OFF or RED]);
bar.writeDisplay;

for every possible setup I would like.

I'd like to have a few patterns.

One pattern would be (basically a shift register running 3 bits, give or take):
100000000000000000000000
110000000000000000000000
111000000000000000000000
011100000000000000000000
001110000000000000000000
000111000000000000000000

You get the idea.

The next would be a purely random set.

The third would be something like this:
101011101000101110100010
100011101011101110101110
100011101110111010101000

Not quite random, there is a code in there. Kinda a "mashed" morse code. But I digress.

vader7071
 
Posts: 78
Joined: Mon Sep 11, 2017 12:45 pm

Re: Need help controlling 24 bar graph (1721)

by vader7071 on Tue Jan 23, 2018 5:15 pm

Ok an update. I pulled some of my old digital knowledge out of storage, and I think I came up with a solution to style 1.

Here is the code I have tossed together, Please help me see if I am correct.

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"


Adafruit_24bargraph bar = Adafruit_24bargraph();

int b = 0;                                        // Which LED are we looking at?
long chestBar = 8;                        // Uses a 32 bit word for bit location

//======Setup======
void setup() {
   bar.begin(0x73);                         // Set the address for the 24 Bar Graph
}

//======Loop======
void loop() {
   for (b; b<24; b++) {                             // loop through all 24 LEDs
      if (bitRead(chestBar,b) == 1) {          // looking at bit number "b" in "chestBar"
         bar.setBar(b, LED_RED);             // if that bit is a 1, set that LED as red
      }
      else {
         bar.setBar(b, LED_OFF);             // if that bit is a 0, set that LED as off
      }
      bar.writeDisplay();                           // write the whole lot to the display
   }
   chestBar << 1;                                    // shift the word "chestBar" one to the left (move the bits over)
   b = 0;                                                 // set "b" back to 0
   if (chestBar == 29360128) {              // used to make adjustments as we near the 24th bit (bit 23, 24, and 25 are 1)
      chestBar = 12582913;                    // change to bit 1, 23, and 24
   }
   if (chestBar == 25165826) {              // used to make adjustments as we near the 24th bit (bit 2, 24, and 25 are 1)
      chestBar = 8388611;                      // change to bit 1, 2, and 24
   }
   if (chestBar == 16777222) {              // used to make adjustments as we near the 24th bit (bit 2, 3, and 25 are 1)
      chestBar = 8;                                 // change to bit 1, 2, and 3
   }
   delay(500);                                       // hold for a half a second before running loop again
}

vader7071
 
Posts: 78
Joined: Mon Sep 11, 2017 12:45 pm

Re: Need help controlling 24 bar graph (1721)

by vader7071 on Fri Jun 14, 2019 8:29 pm

I'd like to see if I can revive this thread.

A year and a half later, I ran into this again. I was able to solve my original question and make the code work, but I have come across a need to write the 24 bit word all at one time rather than one led at the time.

vader7071
 
Posts: 78
Joined: Mon Sep 11, 2017 12:45 pm

Re: Need help controlling 24 bar graph (1721)

by kcl1s on Fri Jun 14, 2019 11:11 pm

A 24 bit word will only give you 2 choices (off and a color or color 1 and color 2). What results are you wanting? What will determine your input?

To change all at once do bar.setBar for the 24 positions then update the bar with bar.writeDisplay.

An uint8_t array may work if you want 3 colors and off. 0 = LED_OFF, 1 = LED_RED, 2 = LED_YELLOW, 3 = LED_GREEN and set the bar to the array value with something like this
Code: Select all | TOGGLE FULL SIZE
  for (int b = 0; b < 24; b++) {
    bar.setBar(b, barArray[b]);
  }
  bar.writeDisplay();



More info will be helpful to find a solution for you.

Fellow hobbyist
Keith

kcl1s
 
Posts: 1354
Joined: Tue Aug 30, 2016 12:06 pm

Please be positive and constructive with your questions and comments.