Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Last active April 12, 2020 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/51d8fa112491b6c8575aa18358ad51f0 to your computer and use it in GitHub Desktop.
Save JeffersGlass/51d8fa112491b6c8575aa18358ad51f0 to your computer and use it in GitHub Desktop.
int SEG_A = 4; //define which pins connect to which segments
int SEG_B = 5;
int SEG_C = 8;
int SEG_D = 7;
int SEG_E = 6;
int SEG_F = 3;
int SEG_G = 2;
int SEG_DOT = 9;
int pins[] = {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DOT};
int numPins = 8;
//Segment data: in order (DOT)GFECDBA
byte DIG_0 = B00111111; // 0 - Segments ABCDEF
byte DIG_1 = B00000110; // 1 - segments BC
byte DIG_2 = B01011011; // 2 - segments ABDEG
byte DIG_3 = B01001111; // 3 - segments ABCDG
byte DIG_4 = B01100110; // 4 - segments BCFG
byte DIG_5 = B01101101; // 5 - segments ACDFG
byte DIG_6 = B01111101; // 6 - segments ACDEFG
byte DIG_7 = B00000111; // 7 - segments ABC
byte DIG_8 = B01111111; // 8 - segments ABCDEFG
byte DIG_9 = B01100111; // 9 - segments ABCFG
int digitData[] = {DIG_0, DIG_1, DIG_2, DIG_3, DIG_4, DIG_5, DIG_6, DIG_7, DIG_8, DIG_9};
int pause = 500;
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < numPins; i++){
pinMode(pins[i], OUTPUT);
}
turnOffAllSegments();
}
void loop() {
// put your main code here, to run repeatedly:
int largestDigit = 9;
for (int i = 0; i <= largestDigit; i++){
displayDigit(i);
delay(pause);
}
}
void turnOffAllSegments(){
for (int i = 0; i < numPins; i++){
digitalWrite(pins[i], HIGH);
}
}
void displayDigit(int num){
turnOffAllSegments();
if (num >=0 && num <= 9){
for (int i = 0; i < numPins; i++){
if (bitRead(digitData[num], i) == 1){
digitalWrite(pins[i], LOW);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment