I use two separate displays with shiftregisters. One is sr_A, second is sr_B.
I have two separate void function; showNumber_A and showNumber_B.
I pass variable to each function. I like to have only one function, but I do not know how to pass which shift register to use.
Can you help me. Please forgive me if I use wrong programming words.
ShiftRegister74HC595<2> sr_A(SDIa, SCLKa, LOADa);
ShiftRegister74HC595<2> sr_B(SDIa, SCLKa, LOADa);
void showNumber_A(int num)
{
digit2 = num % 10;
digit1 = (num / 10) % 10;
//Send them to 7 segment displays
uint8_t numberToPrint[] = { digits[digit1],digits[digit2] };
sr_A.setAll(numberToPrint);
}
void showNumber_B(int num)
{
digit2 = num % 10;
digit1 = (num / 10) % 10;
//Send them to 7 segment displays
uint8_t numberToPrint[] = { digits[digit1],digits[digit2] };
sr_B.setAll(numberToPrint);
}
`
Please post all your code. It would be useful to understand what libraries you are using.
sr_A.setAll(numberToPrint);
What is sr_A (and sr_B) ?
Can you see why we ask that you post a complete sketch ?
b707
November 7, 2022, 7:13pm
4
Use a reference to shift register
void showNumber(int num, ShiftRegister74HC595<2> &sr)
{
digit2 = num % 10;
digit1 = (num / 10) % 10;
//Send them to 7 segment displays
uint8_t numberToPrint[] = { digits[digit1],digits[digit2] };
sr.setAll(numberToPrint);
}
Usage:
showNumber(8, sr_A);
Beat me to it:
using SR2 = ShiftRegister74HC595<2>;
SR2 sr_A(SDIa, SCLKa, LOADa);
SR2 sr_B(SDIa, SCLKa, LOADa);
void showNumber_A(SR2 &sr, int num) {
digit2 = num % 10;
digit1 = (num / 10) % 10;
//Send them to 7 segment displays
uint8_t numberToPrint[] = { digits[digit1], digits[digit2] };
sr.setAll(numberToPrint);
}
1 Like
b707
November 7, 2022, 7:17pm
6
Marmadoc:
ShiftRegister74HC595<2> sr_A(SDIa, SCLKa, LOADa);
ShiftRegister74HC595<2> sr_B(SDIa, SCLKa, LOADa);
You use the same pins for both SR - is it correct?
Thx a lot - it is exactly what I was looking for. Works perfectly.
b707
November 7, 2022, 10:06pm
8
Please mark the problem solved
system
Closed
May 6, 2023, 10:06pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.