i tried a program in which i wanted to display numbers using three separate single digit seven segment that counts 0 - 9 . Each display has a separate push button switch to increment and decrement the number. I used three ports for the data pin( dataPin1, dataPin2 and dataPin3) for each display and only one latch pin and one clock pin for the three displays. This set up didn't work. i just wander if this sis possible. Thanks arduino community for your advice.
This set up didn't work.
Are you latching, clocking, and sending data to one segment at a time? Or, are you latching and clocking while sending data to all three segments?
Are you latching, clocking, and sending data to one segment at a time? Or, are you latching and clocking while sending data to all three segments?
Thanks Mr. PaulS
i am latching , clocking, and sending data to one segment at a time, but using only one microcontroller.
Actually, that was a hint to post your code and your observations about what "it doesn't work" means.
This is what i have sir!
const int dataPin1=2;
const int dataPin2=3;
const int dataPin3=4;
const int clockPin=5;
const int latchPin=6;
const int inc1Pin=7;
const int dec1Pin=8;
const int inc2Pin=9;
const int dec2Pin=10;
const int inc3Pin=11;
const int dec3Pin=12;
int inc1Button=0;
int dec1Button=0;
int inc2Button=0;
int dec2Button=0;
int inc3Button=0;
int dec3Button=0;
int inc1LastButtonState=0;
int dec1LastButtonState=0;
int inc2LastButtonState=0;
int dec2LastButtonState=0;
int inc3LastButtonState=0;
int dec3LastButtonState=0;
int p1Ones=0;
int game1Score=0;
int p2Ones=0;
int game2Score=0;
int p3Ones=0;
int game3Score=0;
int myArray[10]={ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
void setup()
{
pinMode(dataPin1, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(dataPin3, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
for (int x=7;x<13;x++)
{
pinMode(x,INPUT);
}
}
void loop()
{
inc1Button=digitalRead(inc1Pin);
dec1Button=digitalRead(dec1Pin);
inc2Button=digitalRead(inc2Pin);
dec2Button=digitalRead(dec2Pin);
inc3Button=digitalRead(inc3Pin);
dec3Button=digitalRead(dec3Pin);
if(inc1Button!=inc1LastButtonState)
{
if(inc1Button==HIGH)
{
if(game1Score<10)
{
game1Score++;
}
}
}
if(dec1Button!=dec1LastButtonState)
{
if(dec1Button==HIGH)
{
if(game1Score!=0)
{
game1Score--;
}
}
}
if(inc2Button!=inc2LastButtonState)
{
if(inc2Button==HIGH)
{
if(game2Score<10)
{
game2Score++;
}
}
}
if(dec2Button!=dec2LastButtonState)
{
if(dec2Button==HIGH)
{
if(game2Score!=0)
{
game2Score--;
}
}
}
if(inc3Button!=inc3LastButtonState)
{
if(inc3Button==HIGH)
{
if(game3Score<10)
{
game3Score++;
}
}
}
if(dec3Button!=dec3LastButtonState)
{
if(dec3Button==HIGH)
{
if(game3Score!=0)
{
game3Score--;
}
}
}
if(inc1Button==HIGH && dec1Button==HIGH)
{
game1Score=0;
}
if(inc2Button==HIGH && dec2Button==HIGH)
{
game2Score=0;
}
if(inc3Button==HIGH && dec3Button==HIGH)
{
game3Score=0;
}
inc1LastButtonState=inc1Button;
dec1LastButtonState=dec1Button;
inc2LastButtonState=inc2Button;
dec2LastButtonState=dec2Button;
inc3LastButtonState=inc3Button;
dec3LastButtonState=dec3Button;
delay(50);
Score1Update();
Score2Update();
Score3Update();
}
void Score1Update()
{
p1Ones=game1Score;
updateScore1Display();
}
void Score2Update()
{
p2Ones=game2Score;
updateScore2Display();
}
void Score3Update()
{
p3Ones=game3Score;
updateScore3Display();
}
void updateScore1Display()
{
digitalWrite(latchPin,HIGH);
shiftOut(dataPin1,clockPin,MSBFIRST,myArray[p1Ones]);
digitalWrite(latchPin,LOW);
}
void updateScore2Display()
{
digitalWrite(latchPin,HIGH);
shiftOut(dataPin2,clockPin,MSBFIRST,myArray[p2Ones]);
digitalWrite(latchPin,LOW);
}
void updateScore3Display()
{
digitalWrite(latchPin,HIGH);
shiftOut(dataPin3,clockPin,MSBFIRST,myArray[p3Ones]);
digitalWrite(latchPin,LOW);
}
This is what i have sir!
What does it do that you don't want?
What does it not do that you want?
"It doesn't work" is NOT enough to get it fixed.
Thanks Mr PaulS.
These are the things that i need to achieved:
- First i want to control two switches ( increment and decrement) for the first display.
2, second , once the first display reaches 9, i will leave the first two switches and take another two switches to control the next display. again after it reaches 9, i will leave that two switches and operate the next two switches to control the 3rd display. - All of those using only one atmega 328 and using one port for the latch, one port for the clock for the three 74595 for my 3 displays. one port(data) each for each of my 74594.
These are the things that i need to achieved:
Since you won't tell us what the code actually does, good luck with the project.
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
So we can see how you have the hardware connected.
Please no fritzy diagrams.
Thanks.. Tom... ![]()
You are close.
Have the clock in parallel to each, have the latch in parallel to each, have the data to one and then daisy chain to the next, and to the next.
Your code will then send out 3 bytes to update the displays.
MRCLR on all 3 will connect to Vcc (5V), and OE/ will connect to Gnd.
Code will be something like this:
if (digitalRead(decrement1) == LOW){
updateDisplay = 1;
if (digit1>0){
digit1 = digit1 - 1;
}
else {
digit1 = 9;
}
}
if (digitalRead(increment1)==0){
updateDisplay = 1;
digit1 = digit1 + 1;
if (digit1 == 10){
digit1 = 0;
}
}
// repeat for digit2, digit3
if (updateDisplay == 1){
updateDisplay = 0;
digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, fontArray[digit1]);
shiftOut(dataPin, clockPin, MSBFIRST, fontArray[digit2]);
shiftOut(dataPin, clockPin, MSBFIRST, fontArray[digit3]);
digitalWrite (latchPin, HIGH); // outputs change on this rising edge
}
and fontArray will be the software to hardware mapping:
byte fontArray[] = {
0b00111111, // 0 DP-g-f-e-d-c-b-a
0b00000110, // 1 high bit = segment on
// etc up to 9
}
Segment layout
a
f b
g
e c
d DP
in setup(),
pinMode (increment1, INPUT_PULLUP); // button press connects pin to Gnd and reads as LOW
Thanks for the advice Mr. crossroad.
But my ultimate requirement is that each display is independent of each other, means , each has its own inc and dec switch so that i can play them separately without affecting the the other.
Thanks
i tried to daisy chain the data and parallel the clock and latch, but it gives some sort of intermittent output. is there any other way to achieved my objectives? thanks in advance
