I've got project that needed to have some (4) digits display, and had plenty of 7 seg. displays lying around. I didn't have any multiplexers left but have instead wired it up as per this diagram:
I've the wired my duemilanove with the a-dp pins on the 13-6, and the transistors on 5-2.
Getting the right segments on has been a breeze, but I'm finding that if I have any kind of counting logic, the displays dim to about 20%. What I mean by this is that I can have my sketch run with all digits full brightness displaying 8s no problem, but if anywhere in the loop I have a variable that I increment up (say by incrementing up 1 per loop), and change nothing else, the display will go from 100% brightness, to 20% (at best).
Below is the demo code I'm using (there are tons of weird things in it at the moment as I've been desperately trying to track this dimming issue down), and all I have to change to see the effect take place is to uncomment the line at the end of the loop: "//count = count + 1;"
const int sub_delay = 1000;
const int middle_middle = 13;
const int middle_top = 11;
const int middle_bottom = 8;
const int top_left = 12;
const int top_right = 10;
const int bottom_left = 9;
const int bottom_right = 7;
//Build the digit quick table
int digits_all[] = {top_left, top_right, middle_top, middle_bottom, bottom_right, bottom_left, middle_middle};
int digits0[] = {top_left, middle_top, top_right, middle_bottom, bottom_right, bottom_left};
int digits1[] = {top_right, bottom_right};
int digits2[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_left};
int digits3[] = {middle_top, middle_middle, middle_bottom, top_right, bottom_right};
int digits4[] = {};
int digits5[] = {};
int digit_selector0 = 2;
int digit_selector1 = 3;
int digit_selector2 = 4;
int digit_selector3 = 5;
int digit_selectors[] = {digit_selector0, digit_selector1, digit_selector2, digit_selector3};
int last = digits_all;
int last_size = sizeof(digits_all);
int last_selector = digit_selector0;
String test = "12, 13, 10, 8, 7, 9";
int count = 0;
// the setup function runs once when you press reset or power the board
void setup() {
//Initialize the digit segments
for (int c = 0; c < sizeof(digits0); c++) {
//digitalWrite(digits0[c], HIGH);
pinMode(digits0[c], OUTPUT);
}
//demo
//digitalWrite(middle_middle, HIGH);
//digitalWrite(top_left, HIGH);
//digitalWrite(middle_top, HIGH);
//digitalWrite(top_right, HIGH);
//digitalWrite(bottom_left, HIGH);
//digitalWrite(middle_bottom, HIGH);
//digitalWrite(bottom_right, HIGH);
Serial.begin(9600);
}
void turn_off_all (int digit, int digits[], int digits_size, int num) {
last = digits;
last_size = digits_size;
digitalWrite(last_selector, LOW);
last_selector = digit;
digitalWrite(digit, HIGH);
int temp = 1;
if (num == 0) {
digitalWrite(top_left, HIGH);
digitalWrite(top_right, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(bottom_left, HIGH);
digitalWrite(middle_top, HIGH);
digitalWrite(middle_middle, LOW);
}
if (num == 1) {
digitalWrite(top_right, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(top_left, LOW);
digitalWrite(middle_bottom, LOW);
digitalWrite(bottom_left, LOW);
digitalWrite(middle_top, LOW);
digitalWrite(middle_middle, LOW);
}
if (num == 2) {
digitalWrite(middle_top, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(top_right, HIGH);
digitalWrite(bottom_left, HIGH);
digitalWrite(top_left, LOW);
digitalWrite(bottom_right, LOW);
}
if (num == 3) {
digitalWrite(middle_top, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(top_right, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(top_left, LOW);
digitalWrite(bottom_left, LOW);
}
if (num == 4) {
digitalWrite(top_right, HIGH);
digitalWrite(top_left, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_bottom, LOW);
digitalWrite(middle_top, LOW);
digitalWrite(bottom_left, LOW);
}
if (num == 5) {
digitalWrite(top_left, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_top, HIGH);
digitalWrite(top_right, LOW);
digitalWrite(bottom_left, LOW);
}
if (num == 6) {
digitalWrite(top_left, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(bottom_left, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_top, HIGH);
digitalWrite(top_right, LOW);
}
if (num == 7) {
digitalWrite(top_right, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(middle_top, HIGH);
digitalWrite(bottom_left, LOW);
digitalWrite(middle_bottom, LOW);
digitalWrite(middle_middle, LOW);
digitalWrite(top_left, LOW);
}
if (num == 8) {
digitalWrite(top_left, HIGH);
digitalWrite(top_right, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(bottom_left, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_top, HIGH);
}
if (num == 9) {
digitalWrite(top_left, HIGH);
digitalWrite(top_right, HIGH);
digitalWrite(bottom_right, HIGH);
digitalWrite(middle_middle, HIGH);
digitalWrite(middle_top, HIGH);
digitalWrite(middle_bottom, HIGH);
digitalWrite(bottom_left, LOW);
}
}
// the loop function runs over and over again forever
void loop() {
turn_off_all(digit_selector0, digits0, sizeof(digits0), 1);
delay(1000);
//count = count + 1;
}
Any suggestions welcome!
Extra notes: I haven't yet tried another arduino board, but I've never had issues with this particular board before (Though I am hoping to switch to an ESP8622, but that is irrelevant to this issue).
count
is relevant to the function. Is this also the same code you used to turn on all the segments? – SoreDakeNoKoto Nov 14 '16 at 3:18