I wish to display the numbers "1,2,3, and 4" on 2 - 2 digit Seven Segment Displays (SSDs) (CL3621AH Common Cathode). "1" on SSD_1, "2" on SSD_2, etc.
When I run my code, the output is "1" on SSD_1, "2" on SSD_2, "1" on SSD_3, and "4" on SSD_4. If I change the first line in the void Loop function to "byte bits1 = GetBits(7) ;", the outputs become 7,2,7,4.
What I find particularly strange is if I remove the jumper wire from Arduino pin 11 (connects to the second SSD's #10 pin) and touch it to the jumper that is connected to Arduino 9 (connected to pin 5 of the first SSD), I get the expected output of "1,2,3,4".
My sketch is part of a larger project so you may find some variables that don't seem to belong. Sorry if I missed removing them.
Here is my code:
/* Using CL3621AH Common Cathode 2 digit Seven Segment Displays
* Shift register SN74hc595 1 to digital display 9 (SevSeg B)
2 8 (SevSeg C)
3 6 (SevSeg D)
4 7 (SevSeg E)
5 4 (SevSeg F)
6 1 (SevSeg G)
7 not used
8 grnd
9 not used
10 to +5V
11 to arduino 4 CLOCK
12 to arduino 3 LATCH
13 to grnd
14 to arduino 5 DATA
15 to digital display 3 (SevSeg A)
16 to +5V
On 2nd SN74HC595, Pin 11 from first goes to 11 on second
Pin 12 goes to 12
Pin 9 from first goes to 14 on second
*/
#include <stdio.h>
#include <DS1302.h>
#include "SevSeg.h"
const int dataPin = 5; // to 74HC595 pin 14
const int latchPin = 3; // to 74HC595 pin 12
const int clockPin = 4; // to 74HC595 pin 11
const int Digit_1 = 11; // Digital Pin 11 on Arduino controls the Mins Tens Digit (Sev Seg 10)
const int Digit_2 = 12; // Digital Pin 12 on Arduino controls the Hrs Tens Digit (Sev Seg 10)
const int Digit_3 = 9; // Digital Pin 9 on Arduino controls the Hrs Ones Digit (Sev Seg 5)
const int Digit_4 = 10; // Digital Pin 10 on Arduino controls the Mins Ones Digit (Sev Seg 5)
bool decPt = true; // decimal point display flag
void setup() {
// initialize I/O pins
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(Digit_1, OUTPUT); // Mins Tens
pinMode(Digit_2, OUTPUT); // Hrs Tens
pinMode(Digit_3, OUTPUT); // Hrs Ones
pinMode(Digit_4, OUTPUT); // Min Ones
Serial.begin(9600);
}
void loop() {
byte bits1 = GetBits(1) ;
byte bits2 = GetBits(2) ;
byte bits3 = GetBits(3);
byte bits4 = GetBits(4);
for (int t = 0; t < 20; t++) { // Change max value of t to speed up or slow down the amount of time between number progression
digitalWrite(Digit_1, LOW); // Turn on the Tens
digitalWrite(Digit_2, HIGH);
myH1UpdateDisplay(bits1); // display alphanumeric digit for bits1
delay(4);
digitalWrite(Digit_1, HIGH);
digitalWrite(Digit_2, LOW);
myH1UpdateDisplay(bits2); // display alphanumeric digit for bits2
delay(4);
digitalWrite(Digit_2, HIGH);
digitalWrite(Digit_3, LOW); // Turn on the Tens
digitalWrite(Digit_4, HIGH);
myH1UpdateDisplay(bits3); // display alphanumeric digit for bits1
delay(4);
digitalWrite(Digit_3, HIGH);
digitalWrite(Digit_4, LOW);
myH1UpdateDisplay(bits4); // display alphanumeric digit for bits2
delay(4);
digitalWrite(Digit_4, HIGH);
}
}
void myH1UpdateDisplay(byte eightBits) {
digitalWrite(latchPin, LOW); // prepare shift register for data
shiftOut(dataPin, clockPin, LSBFIRST, eightBits); // send data
digitalWrite(latchPin, HIGH); // update display
}
byte GetBits(int someNumber) { // Maps which segments to light up for each number sent as "i" and returns the eightBits
// which is then picked up by the function myH1UpdateDisplay which sents eightBits via the shiftOut call.
switch (someNumber) {
case 0:
return B11111100;
break;
case 1:
return B01100000;
break;
case 2:
return B11011010;
break;
case 3:
return B11110010;
break;
case 4:
return B01100110;
break;
case 5:
return B10110110;
break;
case 6:
return B10111110;
break;
case 7:
return B11100000;
break;
case 8:
return B11111110;
break;
case 9:
return B11110110;
break;
}
}