#include <TimerOne.h>
#define A 2
#define B 4
#define C 6
#define D 7
#define E 8
#define F 3
#define G 5
#define D_1 9
#define D_2 10
#define D_3 11
#define D_4 12
unsigned char unit = 0, ten = 0, hun = 0, thou = 0;
unsigned char pos[4] = {0,0,0,0};
unsigned char digit[10][7]{//row,column
// A,F,B,G,C,D,E
{0,0,0,1,0,0,0},//0
{1,1,0,1,0,1,1},//1
{0,1,0,0,1,0,0},//2
{0,1,0,0,0,0,1},//3
{1,0,0,0,0,1,1},//4
{0,0,1,0,0,0,1},//5
{0,0,1,0,0,0,0},//6
{0,1,0,1,0,1,1},//7
{0,0,0,0,0,0,0},//8
{0,0,0,0,0,0,1}//9
};
void setup() {
for(int i = A; i <= D_4; i++){
pinMode(i, OUTPUT);
digitalWrite(i,HIGH);
if(i >= D_1)
digitalWrite(i,LOW);
}
Timer1.initialize(1000000);
Timer1.attachInterrupt(timerCallback);
Timer1.start();
// put your setup code here, to run once:
}
void loop() {
int j = 0;
for(int k = 0; k < 4; k++)
{
j = pos[k];
for(int l = D_1; l <= D_4; l++)
{
digitalWrite(l,LOW);
}
for(int i = 0; i < 7; i++)
{
digitalWrite(i+A,digit[j][i]);
}
digitalWrite(k+D_1,HIGH);
delay(10);
}
// put your main code here, to run repeatedly:
}
/*
@def function that runs every second
@param none
@return none
*/
void timerCallback(void)
{
if(unit++ >= 9){
unit = 0;
if(ten++ >= 9){
ten = 0;
if(hun++ >= 9){
hun = 0;
if(thou++>= 9){
thou = 0;
}
}
}
}
pos[0] = thou;
pos[1] = hun;
pos[2] = ten;
pos[3] = unit;
}