Thanks for the reply.
do i need to create another number int set of (10 numbers.)?
For two segments, just shift out the first, then the second
Not sure how to shift out the second? do you mean.
something like this?
digitalWrite(latchPin, LOW); // Set latchPin LOW while clocking these 8 bits in to the register
shiftOut(dataPin, clockPin, LSBFIRST, data);
shiftOut(dataPin, clockPin, LSBFIRST, data);
digitalWrite(latchPin, HIGH);
original code
const int latchPin = 5; // Pin connected to Pin 12 of 74HC595 (Latch)
const int dataPin = 6; // Pin connected to Pin 14 of 74HC595 (Data)
const int clockPin = 7; // Pin connected to Pin 11 of 74HC595 (Clock)
int upPin = 12; // pushbutton attached to pin 12
int downPin = 13; // pushbutton attached to pin 13
int currUpState = 1; // initialise currUpState as HIGH
int currDownState = 1; // initialise currDownState as HIGH
int prevUpState = 0;
int prevDownState = 0;
int counter = 0; // initialise counter as zero
int numbers[10] = // Describe each digit in terms of display segments 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{
B11111100,
B01100000,
B11011010,
B11110010,
B01100110,
B10110110,
B10111110,
B11100000,
B11111110,
B11100110,
};
void setup()
{
pinMode(latchPin, OUTPUT); // set SR pins to output
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(upPin, INPUT); // sets pin 12 as pushbutton INPUT
pinMode(downPin, INPUT); // sets pin 13 as pushbutton INPUT
}
void loop()
{
currUpState = digitalRead(upPin);
if (prevUpState != currUpState) // has the state changed from
{ // HIGH to LOW or vice versa
prevUpState = currUpState;
if (currUpState == HIGH) // If the button was pressed
counter++;
if(counter > 8) counter = 0; // increment the counter by one
}
if(counter > 8)
counter--;
show(numbers[counter]); // display the current digit
currDownState = digitalRead(downPin);
if (prevDownState != currDownState) // has the state changed from
{ // HIGH to LOW or vice versa
prevDownState = currDownState;
if (currDownState == HIGH) // If the button was pressed
counter--; // decrement the counter by one
}
if(counter < 0)
counter++;
show(numbers[counter]); // display the current digit
}
void show( byte number)
{
// Use a loop and a bitwise AND to move over each bit that makes up
// the seven segment display (from left to right, A => G), and check
// to see if it should be on or not
for(int j = 0; j <= 7; j++)
{
byte toWrite = number & (B10000000 >> j);
if(!toWrite) {
continue;
} // If all bits are 0 then no point writing it to the shift register,so break out and
//move on to next segment.
shiftIt(toWrite); // Otherwise shift it into the register
}
}
void shiftIt (byte data)
{
digitalWrite(latchPin, LOW); // Set latchPin LOW while clocking these 8 bits in to the register
shiftOut(dataPin, clockPin, LSBFIRST, data);
digitalWrite(latchPin, HIGH); //set latchPin to high to lock and send data
// put delay here if you want to see the multiplexing in action!
// delay(10);
}