int ASeg = 13;
int BSeg = 12;
int CSeg = 11;
int DSeg = 10;
int ESeg = 9;
int FSeg = 8;
int GSeg = 7;
int Decimal = 2;
int a1 = 6;
int a2 = 5;
int a3 = 4;
int a4 = 3;
// set variable
long n = 0;
int x = 200;
int del = 1000; // fine adjustment for clock
void setup()
{
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
pinMode(a3, OUTPUT);
pinMode(a4, OUTPUT);
pinMode(ASeg, OUTPUT);
pinMode(BSeg, OUTPUT);
pinMode(CSeg, OUTPUT);
pinMode(DSeg, OUTPUT);
pinMode(ESeg, OUTPUT);
pinMode(FSeg, OUTPUT);
pinMode(GSeg, OUTPUT);
pinMode(Decimal, OUTPUT);
}
void loop()
{
clearLEDS(); // Eliminating ghost
pickDigit(1); // Display position 1
pickNumber((n/x/1000)%10); // Display number
delayMicroseconds(del); // Time adjustment
clearLEDS();
pickDigit(2);
pickNumber((n/x/100)%10);
delayMicroseconds(del);
clearLEDS();
pickDigit(3);
pickNumber((n/x/10)%10);
delayMicroseconds(del);
clearLEDS();
pickDigit(4);
pickNumber(n/x%10);
delayMicroseconds(del);
n++;
}
// Select display position
void pickDigit(int x)
{
digitalWrite(a1, LOW);
digitalWrite(a2, LOW);
digitalWrite(a3, LOW);
digitalWrite(a4, LOW);
switch(x)
{
case 1:
digitalWrite(a1, HIGH);
break;
case 2:
digitalWrite(a2, HIGH);
break;
case 3:
digitalWrite(a3, HIGH);
break;
case 4:
digitalWrite(a4, HIGH);
break;
}
}
// select display number
void pickNumber(int x)
{
switch(x) {
case 1: one(); break;
case 2: two(); break;
case 3: three(); break;
case 4: four(); break;
case 5: five(); break;
case 6: six(); break;
case 7: seven(); break;
case 8: eight(); break;
case 9: nine(); break;
default: zero(); break;
}
}
void clearLEDS() // clear the screen
{
digitalWrite(ASeg, HIGH);
digitalWrite(BSeg, HIGH);
digitalWrite(CSeg, HIGH);
digitalWrite(DSeg, HIGH);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, HIGH);
digitalWrite(GSeg, HIGH);
}
//Display function ‘0-9’
void zero() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, LOW);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, HIGH);
digitalWrite(Decimal, LOW);
}
void one() {
digitalWrite(ASeg, HIGH);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, HIGH);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, HIGH);
digitalWrite(GSeg, HIGH);
digitalWrite(Decimal, HIGH);
}
void two() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, HIGH);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, LOW);
digitalWrite(FSeg, HIGH);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, LOW);
}
void three() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, HIGH);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, HIGH);
}
void four() {
digitalWrite(ASeg, HIGH);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, HIGH);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, LOW);
}
void five() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, HIGH);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, HIGH);
}
void six() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, HIGH);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, LOW);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, LOW);
}
void seven() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, HIGH);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, HIGH);
digitalWrite(Decimal, HIGH);
}
void eight() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, LOW);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, LOW);
}
void nine() {
digitalWrite(ASeg, LOW);
digitalWrite(BSeg, LOW);
digitalWrite(CSeg, LOW);
digitalWrite(DSeg, LOW);
digitalWrite(ESeg, HIGH);
digitalWrite(FSeg, LOW);
digitalWrite(GSeg, LOW);
digitalWrite(Decimal, HIGH);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
sevseg1:DIG1
sevseg1:DIG2
sevseg1:DIG3
sevseg1:DIG4
sevseg1:COM
sevseg1:CLN