Last active
October 18, 2015 01:02
-
-
Save tnoborio/e23531b9ab9034e6c15f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int a = ; | |
const int b = ; | |
const int c = ; | |
const int d = ; | |
const int e = ; | |
const int f = ; | |
const int g = ; | |
const int p = ; | |
const int d1 = 1; | |
const int d2 = 10; | |
const int d3 = 4; | |
const int d4 = 6; | |
const boolean isAnode = false; | |
int time = 0; | |
void setup() { | |
for (int i = 1; i <= 12; i = i + 1) { | |
pinMode(i, OUTPUT); | |
} | |
} | |
void on(int pin) { | |
if (isAnode) { | |
digitalWrite(pin, HIGH); | |
} else { | |
digitalWrite(pin, LOW); | |
} | |
} | |
void off(int pin) { | |
if (isAnode) { | |
digitalWrite(pin, LOW); | |
} else { | |
digitalWrite(pin, HIGH); | |
} | |
} | |
void reset(int digiPin) { | |
off(d1); | |
off(d2); | |
off(d3); | |
off(d4); | |
on(digiPin); | |
on(a); | |
on(b); | |
on(c); | |
on(d); | |
on(e); | |
on(f); | |
on(g); | |
on(p); | |
} | |
void one() { | |
off(b); | |
off(c); | |
} | |
void two() { | |
off(a); | |
off(b); | |
off(g); | |
off(e); | |
off(d); | |
} | |
void three() { | |
off(a); | |
off(b); | |
off(g); | |
off(c); | |
off(d); | |
} | |
void four() { | |
off(f); | |
off(g); | |
off(b); | |
off(c); | |
} | |
void display(int num) { | |
switch (num) { | |
case 1: | |
one(); | |
break; | |
case 2: | |
two(); | |
break; | |
case 3: | |
three(); | |
break; | |
case 4: | |
four(); | |
break; | |
} | |
} | |
void loop() { | |
int num = (time / 125); | |
reset(d1); | |
display(num / 1000 % 10); | |
delay(2); | |
reset(d2); | |
display(num / 100 % 10); | |
delay(2); | |
reset(d3); | |
display(num / 10 % 10); | |
delay(2); | |
reset(d4); | |
display(num % 10); | |
delay(2); | |
time += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment