My first thought was "we need seven dots if we want to display the numbers from 1 to 6 on a dice". When you wanna use a microcontroller that has only six pins available, and one being the reset (so that's five), you have to find a solution. I was ready to dive into charlyplexing, but I quickly realized that six of these dots were always in pair : we in fact need just four pins. one for the central dot for odd numbers, and three for the pairs used for even numbers. See the schematics on the previous log to see how it's routed.
I also wanted to have a smooth on and off dimming. That implies PWM, which is easy to do on a microcontroller when you have one or two leds. Usually you tie the led to an output driven by the uC. but the ATTiny only has three of its pins that can be driven in such a way. After a bit of thinking, I implemented a quite simple PWM for all leds at once. A timer is used with two of its interrupts :
- On overflow (loop back to 0) all the leds are set, according to their state (i.e. for a three, only a diagonal is set and will lit). The change of duty cycle is also handled here, but I'll come back to it in a later log.
- On compare match (duty cycle) all the leds are shut.
It's probably a bit less efficient than driving the leds directly from the PWM pins, but all the leds are dimmable. The only drawback is they are not independent. That's not a big deal in that case.
Here is the code of the interrupts. As you can see it's straightforward :
ISR(TIMER1_OVF_vect){
// Clearing all four leds)
PORTB &= ~(0b1111);
// overflow counter
if(++overflowCounter >= queueOut->fade.duration){
overflowCounter = 0;
overflow = true;
}
}
ISR(TIMER1_COMPA_vect){
// Set all four leds to their predefined values
if(OCR1A != 255) PORTB |= pinState;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.