Created
July 8, 2020 22:16
-
-
Save jonlorusso/0d3fc86504acb9ae2fdac0922f7586de to your computer and use it in GitHub Desktop.
This file contains 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
int digitToDisplay = 1234; | |
int latchPin = 1; | |
int clockPin = 3; | |
int dataPin = 0; | |
int digits[4][2] = { | |
{ B11111110, B01011111 }, | |
{ B11110111, B01011111 }, | |
{ B11110110, B11011111 }, | |
{ B11110110, B01111111 } | |
}; | |
int top[2] = { B11111011, B11111111 }; | |
int topright[2] = { B11111111, B10111111 }; | |
int bottomright[2] = { B11111111, B11110111 }; | |
int bottom[2] = { B11111111, B11111101 }; | |
int bottomleft[2] = { B11111111, B11111110 }; | |
int topleft[2] = { B11111101, B11111111 }; | |
int middle[2] = { B11111111, B11101111 }; | |
int dp[2] = { B11111111, B11111011 }; | |
int nil[2] = { B11111111, B11111111 }; | |
int digitSegments[10][8] = { | |
{ top, topleft, topright, bottomleft, bottomright, bottom, nil, nil }, | |
{ topright, bottomright, nil, nil, nil, nil, nil, nil }, | |
{ top, topright, middle, bottomleft, bottom, nil, nil, nil }, | |
{ top, topright, middle, bottomright, bottom, nil, nil, nil }, | |
{ topleft, topright, middle, bottomright, nil, nil, nil, nil }, | |
{ top, topleft, middle, bottomright, bottom, nil, nil, nil }, | |
{ top, topleft, middle, bottomleft, bottomright, bottom, nil, nil }, | |
{ top, topright, bottomright, nil, nil, nil, nil, nil }, | |
{ top, topleft, topright, middle, bottomleft, bottomright, bottom, nil }, | |
{ top, topleft, topright, middle, bottomright, nil, nil, nil } | |
}; | |
void setup() { | |
pinMode(latchPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
pinMode(dataPin, OUTPUT); | |
// attachInterrupt(2, incrementDigit, RISING); | |
MCUCR |= B00000011; //watch for rising edge | |
GIMSK |= B01000000; //enable external interrupt | |
SREG |= B10000000; //global interrupt enable | |
} | |
void displaySegment(int digit[], int segment[]) { | |
digitalWrite(latchPin, LOW); | |
shiftOut(dataPin, clockPin, MSBFIRST, digit[0] & segment[0]); | |
shiftOut(dataPin, clockPin, MSBFIRST, digit[1] & segment[1]); | |
digitalWrite(latchPin, HIGH); | |
delayMicroseconds(10); | |
} | |
void loop() { | |
int displayDigits[] = { 0, 0, 0, 0 }; | |
int x = digitToDisplay; | |
int i = 3; | |
while (x > 0) { | |
displayDigits[i] = x % 10; | |
x = x / 10; | |
i = i - 1; | |
} | |
for (int i = 3; i >= 0; i--) { | |
for (int j = 0; j < sizeof(digitSegments[displayDigits[i]])/sizeof(digitSegments[displayDigits[i]][0]); j++) { | |
displaySegment(digits[i], digitSegments[displayDigits[i]][j]); | |
} | |
} | |
} | |
ISR(INT0_vect) { | |
digitToDisplay++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment