Setup:
- ( 8 ) 1" blue 16-segment displays https://www.sparkfun.com/products/9933 multiplexed together
- (2) MBI5026 constant current driver ic
- (1) UDN2981 driver
The entire setup is more/less borrowed from the people over at Evil Mad Science from the AlphaClock5. All of the code works and I've gotten everything working but I'm having difficulty altering the borrowed code from the alphaclock5 to better adjust the led intensity.
Any suggestions on how I'd go about customizing the the brightness levels based on my displays? Code follows:
void refreshDisplay()
{
byte i,j; //Dummy variables
unsigned int offPeriod, onPeriod;
byte tempBright = MainBright;
if (tempBright == 0)
{
digitalWrite(OE, HIGH); //Blank outputs
}
else if (tempBright < 5)
{
offPeriod = 240;
if (tempBright == 2)
offPeriod = 60;
if (tempBright == 3)
offPeriod = 15;
if (tempBright == 4);
offPeriod = 3;
i = 0;
while (i < 32)
{
j = 0;
while (j < 8)
{
shift_data(bufl1[j], bufh1[j], bufh2[j]);
//Enable Digit anode
digitalWrite(digit[j], HIGH);
//Enable led driver
digitalWrite(OE,LOW);
byte SREGtemp = SREG;
//Disable interrupts to avoid timing inconsistancies during short on bursts
cli();
//Use assembly language call 'nop' (no operation) for extremely short delay (62.5 ns)
asm volatile("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t");
//Enable interrupts
sei();
SREG = SREGtemp;
digitalWrite(OE,HIGH);
digitalWrite(digit[j],LOW);
SREGtemp = SREG;
//Disable interrupts to avoid timing inconsistancies during short on bursts
cli();
delayMicroseconds(offPeriod);
//Enable interrupts
sei();
SREG = SREGtemp;
j++;
}
i++;
}
}
else
{
//if (tempBright > 12)
//tempBright = 13;
onPeriod = 15 + ((tempBright - 4) * (tempBright - 4) ) * 2; // Nonlinear brightness scale!
offPeriod = 178 - onPeriod;
i = 0;
while (i < 12)
{
j = 0;
while (j < 8)
{
//analogWrite(OE,0);
shift_data(bufl1[j], bufh1[j], bufh2[j]);
//Enable Digit anode
digitalWrite(digit[j], HIGH);
//Enable led driver
digitalWrite(OE,LOW);
byte SREGtemp = SREG;
//Disable interrupts to avoid timing inconsistancies during short on bursts
cli();
delayMicroseconds(onPeriod);
//Enable interrupts
sei();
SREG = SREGtemp;
//digitalWrite(OE,HIGH);
digitalWrite(digit[j],LOW);
digitalWrite(OE,HIGH);
SREGtemp = SREG;
//Disable interrupts to avoid timing inconsistancies during short on bursts
cli();
delayMicroseconds(offPeriod);
//Enable interrupts
sei();
SREG = SREGtemp;
j++;
}
i++;
}
}
}