Skip to content

Instantly share code, notes, and snippets.

@barakamwakisha
Created November 15, 2022 09:42
Show Gist options
  • Select an option

  • Save barakamwakisha/0adbc25190ef9161426c6a76bfa66736 to your computer and use it in GitHub Desktop.

Select an option

Save barakamwakisha/0adbc25190ef9161426c6a76bfa66736 to your computer and use it in GitHub Desktop.
Arduino code that displays 0 to 9 on a common cathode 7 Segment Display
/* assigning Arduino pins for the seven-segment display */
int segPins[] = {3, 2, 8, 7, 6, 4, 5};
/* declaring an array of the number from 0 to 9 in the order from a of g */
byte segCode[10][7] = {
// a b c d e f g
{ 1, 1, 1, 1, 1, 1, 0},
{ 0, 1, 1, 0, 0, 0, 0},
{ 1, 1, 0, 1, 1, 0, 1},
{ 1, 1, 1, 1, 0, 0, 1},
{ 0, 1, 1, 0, 0, 1, 1},
{ 1, 0, 1, 1, 0, 1, 1},
{ 1, 0, 1, 1, 1, 1, 1},
{ 1, 1, 1, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 0, 1, 1},
};
void displayDigit(int digit) {
for (int a = 0; a < 7; a++) {
digitalWrite(segPins[a], segCode[digit][a]);
}
}
void setup() {
for (int a=0; a < 7; a++) {
pinMode(segPins[a], OUTPUT);
}
}
void loop(){
for (int b = 0; b < 10; b++){
displayDigit(b);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment