Help coding bit register(s)

Big time fan of the arduino here, but just starting out. Long time lurker on these boards, but now I want to join in on all the fun here. :slight_smile:

Ok background:

I recently purchased a 12" Milone eTape for reading the level of liquid in a container. Now I would like to interface that using two shift registers (74hc595n) two one digit 7 segment displays (common cathode).

I have the code for taking the measurements from the e-tape and converting to % full all working printing out to serial. now I am trying to send those two digits (since I have it set to never >= 100%) to the two displays, and I can't seem to wrap my brain around using the shift register system. Percent comes out as an int btw.

I wired and ran the examples on

Currently it's cycling through example 3 flawlessly. Using the 7 seg displays instead of 8 LEDs.

Now I believe that I should use something like the coding used on

Located in the comments (comment 3 from top I believe)

Because they implement a very clever way of separating the digits translating that to the binary that the 7segment displays and sending them through the register. But then when I tried to implement the code in the last link I think I realized that I'm out of my depth and decided to come here for help.

All I wanted to do with my 'work in progress' code was to show "percentFull" on the two displays so I could then rout what's being printed in my working code to be printed on the displays.

Sorry for the lack of comments, been frustratingly trying multiple different things.
Too many frustrating things today, please somebody give me direction or help!

Working eTape code
#define SERIESRESISTOR 560
#define SENSORPIN A0
#define sensorMax 2398
#define sensorMin 350
void setup(void)
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
}
void loop(void)
{
  float sensorValue = analogRead(A0);
  Serial.print(sensorValue);
  Serial.print("          ");
  
  sensorValue = (1024 / sensorValue) - 1;
  sensorValue = SERIESRESISTOR / sensorValue;
  Serial.print(sensorValue);
  Serial.print("          ");
  
  float deptha = sensorMax - sensorValue;
  float depthb = sensorMax - sensorMin;
  int percentFull = (deptha / depthb) * 100;
  
  Serial.print(percentFull);
  Serial.println("%");
  
  delay(1000);
}
WORKINPROGRESS
 
const int clockPin = 12;
const int latchPin = 11;
const int dataPin = 8;
const byte digit[10] =
{
  B00111111,
  B00000110,
  B01011011,
  B01001111,
  B01100110,
  B01101101,
  B01111101,
  B00000111,
  B01111111,
  B01101111
};
int digitBuffer[2] = {0};
int digitScan = 0;
float percentFull;
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
}
void updateDisp() 
{
  /*
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);
  delayMicroseconds(2);
  */
  
  
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  digitalWrite(latchPin, HIGH);
  
  digitScan++;
  if(digitScan>2) digitScan=0;
}
void loop()
{
  int percentFull = 25;
  digitBuffer[1] = int(percentFull)/10;
  digitBuffer[0] = int(percentFull)%10;
  
  delay(4);
  updateDisp();
}

It might help if you tell us what your current code does and what you expect it to do. Does the 7-segment-display show anything? From your code I would expect it to show the two digits one after the other on both modules simultaneously in a fast repetition.

Try replacing

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  digitalWrite(latchPin, HIGH);
  
  digitScan++;
  if(digitScan>2) digitScan=0;

by

  digitScan = 0;
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan++]]);
  shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);
  digitalWrite(latchPin, HIGH);

Post the schematics (or a photo) of your wiring, because the above code expect the two chips to be daisy chained.

I followed the directions from the shiftout tutorial (first link in Op) and things are hooked up exactly like in that tutorial. Just instead of the 16 LEDs, 2x 7 segment 1 digit displays.

But I put that schematic from the tutorial up and took a couple of snapshots.

I would like to just show two numbers (represented as percentFull), one on each 7 segment display.

It says that, if two bytes are sent the first byte goes through the first register and into the second, and the first stays in the first, because it pushes the second out.

So doesn't that mean if I send two bytes( as signified in the 'digit' array) the correct lights will light up on the 7 segment?

So doesn't that mean if I send two bytes( as signified in the 'digit' array) the correct lights will light up on the 7 segment?

Yes, but you didn't do that, my code change should do that. Have you tried it?