Hi there, so I've been playing with one of these sparkfun 4 digit/7 segment displays for a couple days now. And well the things fun, but its a bit needy on pins, so im trying to adapt it to run off of a shift register (74HC595 register specifically). I had been running into a problem yesterday where what was happening was the numbers were getting transposed over a digit. This had been because in my code, i was turning on a new digit without shutting the last one off and updating the shift reg. (like dig 1 would show 4, 2 would show 1, 3 would show 2 and 4 would show 3. However upon close inspection, 1 was dimly lit with 1, 2 was dimly 2, 3 was 3 and 4 was 4).
I tackled the code a bit and am trying to shut off things quick enough. and well currently, the screen shows up with the proper numbers in the proper places, however each digit is extremely dim (basically useless) I can get it brighter by dropping down a few resistor sizes, but im pretty sure bad things will happen if i go down that route.
Currently I'm still trying different fixes that come to my mins, but if anyone might have some insight on how to help me, it would be greatly appreciated.
So for the basic segments of code I have
void setup()
{
pinMode(datapin, OUTPUT); //datapin is the SER pin on the shift reg
digitalWrite(datapin, LOW);
pinMode(clockpin, OUTPUT);// clock is serclk
digitalWrite(clockpin, LOW);
pinMode(output, OUTPUT);// output is the rclk pin
digitalWrite(output, LOW);
pinMode(enable, OUTPUT); // enable is the OE pin (which is actually tied to GND, i was experimenting with controlling it directly)
digitalWrite(enable, HIGH);
pinMode(dig1, OUTPUT); //these are pins 2,3,4,5 which when held high, will turn that digit of the screen on, and low will shut it off
pinMode(dig2, OUTPUT);
pinMode(dig3, OUTPUT);
pinMode(dig4, OUTPUT);
digitalWrite(dig1, LOW);
digitalWrite(dig2, LOW);
digitalWrite(dig3, LOW);
digitalWrite(dig4, LOW);
}
void printnumb(char digit)
{
digitalWrite(output, LOW); // put the output low so in a min i can pull it high and output the new batch of pinmodes
switch(digit)
{
case '0':
shiftOut(datapin, clockpin, LSBFIRST, B00000011); // basic shiftout for each of the different number (and letter) cases
break;
case '1':
shiftOut(datapin, clockpin, LSBFIRST, B10011111);
break;
// goes on to 9
}
digitalWrite(output, HIGH); // when thrown high, updates the output of the shift reg, and screen lights up
}
void convert(int y) //reason for the char in the first switch case was because ill also be displaying a -,C,H and rdy on the screen.
//So this here is to convert the incoming int into the char needed.
{
switch(y)
{
case 0:
printnumb('0'); // in each case, call the function form above for each specific case
break;
// on through 9 aswell
}
}
void digit1(int x)
{
digitalWrite(dig1, LOW); // shut off all the digits, so that i dont accidentally get a number from 1 of the other digits showign up on the wrong spot
digitalWrite(dig2, LOW);
digitalWrite(dig3, LOW);
digitalWrite(dig4, LOW);
convert(x); // but the int from later code into the converter to "make" the char needed, guess i could really skip the converter
//and just go straight from int to the shiftout, don't feel like it though.
digitalWrite(dig1, HIGH); // turn this digit on with the shift reg's current output, and it should
}
// theres another one for dig 2 3 and 4.
void loop()
{
digit1(1);
digit2(2);
digit3(3);
digit4(4);
}