Shift Register Algorithm

OK, so I am looking for a little help here on getting two rows of 10 LEDs and a couple other characters converted to hex to feed into a shift register. The goal is to flash the temperature in Red or Blue, depending on the temp. It is printing from a row of LEDs, and it will 'backup' to display 72 degrees, yes.

Configuration:

For the purpose of explaining, I am using 3 x 8bit registers serially ordered as attached and I have provided two examples.

You can see that in the two examples I create 3 binary and 3 hex numbers, one for each register, so that makes sense, yeah?

Now to program it.... I am really struggling with how to order this, but I think I am close. I want to look to build a binary array this way: My Example is to flash 72F without a message: It illuminates:

RED7[] ; delay(1000); //pseudo
RED2
FARH

I define RED7[20] as:

00000001000000000000

I add wether it is Negative

0

I then add if there is a Message (the M)

001

Put it all together:

int Display[] = 000000010000000000000001 //pseudo, I'm fine feeding this bunch of numbers into Display[]

now to parse out the binary to the three registers (in serial)?

What is the best way to do that? I am using ShiftOut().

for (int j = 0; j < 24; j++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, Display[j]);
digitalWrite(latchPin, HIGH);
}

anyone see a cleaner way to accomplish this?

TwoColorThermometer.pdf (22 KB)

Could you maybe rewrite that in English, or try Google translate?

You can see that in the two examples I create 3 binary and 3 hex numbers, one for each register, so that makes sense, yeah?

Hex or binary, they're just different ways of expressing the same thing.

I define RED7[20] as:

00000001000000000000

Nope, lost me there.
What is Red7?
One of the characters from Star Wars Episode 4?

AWOL:
What is Red7?
One of the characters from Star Wars Episode 4?

XD

If you look at the table attached, RED7 [20] would be the first 20 digits in the sequence, in the first example. Register A pin 7 is 1 , the rest are zeros

It represents the illumination of the red 7 in the LED matrix. There are 10 red, and 10 blu

sorry not to be clear enough

int Display[] = 000000010000000000000001 //pseudo, I'm fine feeding this bunch of numbers into Display[]

No you are not fine.
That is just a single number way way too big to feed into an int.

anyone see a cleaner way to accomplish this?

Sure if we knew what "this" actually is.
I think you are a bit mixed up with what an array is.

It helps to post real code, that is stuff that has seen the inside of the IDE, not just speculative rubbish like this.

Grumpy_Mike:

int Display[] = 000000010000000000000001 //pseudo, I'm fine feeding this bunch of numbers into Display[]

No you are not fine.
That is just a single number way way too big to feed into an int.

its and array filled with zeros or ones

Grumpy_Mike:
I think you are a bit mixed up with what an array is.

It helps to post real code, that is stuff that has seen the inside of the IDE, not just speculative rubbish like this.

I do actually know what an array is, thanks!

So now we know how you decided on a name. If you don't want to help, don't trouble yourself. [I can never understand why someone sits on a forum and berates people looking for help]

I want to build an array of binary numbers, push it out to the shift register in ones and zeroes and latch it.

I want to build an array of binary numbers,

The numbers are already binary - why do you need to expand them into a larger array?

I do actually know what an array is, thanks!

You could have fooled me with:-

int Display[] = 000000010000000000000001 //pseudo, I'm fine feeding this bunch of numbers into Display[]
its and array filled with zeros or ones

That is not an array being filled with ones and zeros.
This is an array being filled with ones and zeros

byte display[] = {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1}

If you don't want to help, don't trouble yourself. [I can never understand why someone sits on a forum and berates people looking for help]

Only if you ask for sensible help instead of incomprehensible ramblings, will you get help.

I want to build an array of binary numbers, push it out to the shift register in ones and zeroes and latch it.

The shift out function will move out one byte at a time. So you define your byte array to have your bytes in it not bits.
Like this:-

byte MyArray [] = {0x12, 0xC4, 0x62};

// then shift it out to the three shift registers with
 digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, myArray[0]);  
    shiftOut(dataPin, clockPin, LSBFIRST, myArray[1]);  
     shiftOut(dataPin, clockPin, LSBFIRST, myArray[2]);   
     digitalWrite(latchPin, HIGH);

Sounds like you could also use an unsigned long (32 bits) that you shift out as bytes.

Let's see if I understand what you need. You have three daisy-chained shift registers and want to know a good way to send you data to them? First you need a data structure to represent the 24 bits you are going to send to the shift registers. A three byte array should do nicely. Then you need to write some code to set the desired bits in the array. And finally, you need to write some code to shift out the three bytes. Keep in mind the bit order as you ponder this.

OK guys, I have what I think is enough to get me started.
I'll come back with some code and tender it for further criticism

get ready Grumpy_Mike!

Grumpy_Mike:
The shift out function will move out one byte at a time. So you define your byte array to have your bytes in it not bits.
Like this:-

OK, I am back.

Taking in that I am passing bytes and not bits (thanks guys), I came up with this but I have one more request for help. How do I pass the For Loop index to the variable name, as highlighted in the code here?

It isn't complete but I only need advice on this to finish up, I believe.

Also, did I mash in the Message Flag correctly by using the pipe?

int latchPin = 3;
int clockPin = 4;
int dataPin  = 5;
//Declare the number portion of the binary arrays
const byte Red0 [3] = {0x80,0x00,0x00};
const byte Red1 [3] = {0x40,0x00,0x00};
const byte Red2 [3] = {0x20,0x00,0x00};
const byte Red3 [3] = {0x10,0x00,0x00};
const byte Red4 [3] = {0x08,0x00,0x00};
const byte Red5 [3] = {0x04,0x00,0x00};
const byte Red6 [3] = {0x02,0x00,0x00};
const byte Red7 [3] = {0x01,0x00,0x00};
const byte Red8 [3] = {0x00,0x80,0x00};
const byte Red9 [3] = {0x00,0x40,0x00};
const byte Blu0 [3] = {0x00,0x20,0x00};
const byte Blu1 [3] = {0x00,0x10,0x00};
const byte Blu2 [3] = {0x00,0x08,0x00};
const byte Blu3 [3] = {0x00,0x04,0x00};
const byte Blu4 [3] = {0x00,0x02,0x00};
const byte Blu5 [3] = {0x00,0x01,0x00};
const byte Blu6 [3] = {0x00,0x00,0x80};
const byte Blu7 [3] = {0x00,0x00,0x40};
const byte Blu8 [3] = {0x00,0x00,0x20};
const byte Blu9 [3] = {0x00,0x00,0x10};
//Negative or Positive?
const byte Neg =0x08;
//Farhenheit or Celcius
const byte Farhenheit = 0x04;
const byte Celc = 0x02;
const byte message = 0x01;
byte tagmessage;
int outdoorTemp= -18;
boolean farh = true;
boolean outdoor=true;
boolean IsMessage = true;
char digit[3];
int firstdigit;
int seconddigit;
int thirddigit;
int t;


void setup()
{
  Serial.begin(19200);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop()
{
  if (outdoorTemp > 0){
    firstdigit = outdoorTemp/100;
    if (firstdigit==1){ 
      t =outdoorTemp-100;
    }
    else{
      t=outdoorTemp;
    }
    seconddigit = t/10;
    thirddigit = outdoorTemp/10 % 10;
    }
    
    if (IsMessage){
      tagmessage = Red1[2] | message;// turn on the last bit by mashing the message flag into the last byte
     }
     else{
       tagmessage= Red1[2];
     }
     digitalWrite(latchPin, LOW);
     shiftOut(dataPin, clockPin, LSBFIRST, Red1[0]);  
     shiftOut(dataPin, clockPin, LSBFIRST, Red1[1]);  
     shiftOut(dataPin, clockPin, LSBFIRST, tagmessage);   
     digitalWrite(latchPin, HIGH);
     //}
     delay(1000);
/*
    if (IsMessage){
      for (int i=seconddigit;i<seconddigit+1;i++)
      {
      tagmessage = Red{???} [2] | message;//*******************
      }
    }
    else 
    {
      tagmessage = Red{???}[2]; *****************************
    }
        shiftOut(dataPin, clockPin, LSBFIRST, Red1[0]);  
    shiftOut(dataPin, clockPin, LSBFIRST, Red1[1]);  
    shiftOut(dataPin, clockPin, LSBFIRST, tagmessage);   
    digitalWrite(latchPin, HIGH);
    delay(1000);
*/
   
   // and so on... 
}

I'll solve the negative number garbage in the temperature reading, but I'm stuck here.

You could try something like this...

const byte Red[10] [3] = {
{0x80,0x00,0x00},
{0x40,0x00,0x00},
{0x20,0x00,0x00},
{0x10,0x00,0x00},
{0x08,0x00,0x00},
{0x04,0x00,0x00},
{0x02,0x00,0x00},
{0x01,0x00,0x00},
{0x00,0x80,0x00},
 {0x00,0x40,0x00}};

And instead of a for loop...

    if (IsMessage){
      tagmessage = Red[seconddigit] [2] | message;//*******************
    }

DavidOConnor:
You could try something like this...

const byte Red[10] [3] = {

{0x80,0x00,0x00},
{0x40,0x00,0x00},
{0x20,0x00,0x00},
{0x10,0x00,0x00},
{0x08,0x00,0x00},
{0x04,0x00,0x00},
{0x02,0x00,0x00},
{0x01,0x00,0x00},
{0x00,0x80,0x00},
{0x00,0x40,0x00}};




And instead of a for loop...



if (IsMessage){
      tagmessage = Red[seconddigit] [2] | message;//*******************
    }

great, and thanks!