Skip to content

Instantly share code, notes, and snippets.

@mrizvic
Created September 5, 2015 20:03
Show Gist options
  • Save mrizvic/09fac76783682cf0d401 to your computer and use it in GitHub Desktop.
Save mrizvic/09fac76783682cf0d401 to your computer and use it in GitHub Desktop.
volatile byte muxCount = 0;
volatile byte mask[16] = {113, 114, 116, 120, 177, 178, 180, 184, 209, 210, 212, 216, 225, 226, 228, 232};
volatile byte ledSegments1[16];
byte n=0;
void setup() {
cli();
DDRD = 255; // sets Arduino pins 0 to 7 as outputs
//timer setup
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 58000;
TCCR1B = _BV(CS10); //prescaler
TIMSK1 = _BV(TOIE1); //enable overflow interrupt
sei();
}
ISR(TIMER1_OVF_vect) {
TCNT1 = 58000;
if (ledSegments1[muxCount]) { PORTD = mask[muxCount]; } else { PORTD = 0; }
muxCount = ++muxCount % 16;
}
void loop() {
delay(70);
// perform 'clear screen'
ledSegments1[0]=0;
ledSegments1[1]=0;
ledSegments1[2]=0;
ledSegments1[3]=0;
ledSegments1[4]=0;
ledSegments1[5]=0;
ledSegments1[6]=0;
ledSegments1[7]=0;
ledSegments1[8]=0;
ledSegments1[9]=0;
ledSegments1[10]=0;
ledSegments1[11]=0;
ledSegments1[12]=0;
ledSegments1[13]=0;
ledSegments1[14]=0;
ledSegments1[15]=0;
// bit shift
ledSegments1[n] = 1;
ledSegments1[(n + 8) % 16] = 1;
n = ++n % 16;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment