Created
November 15, 2022 09:42
-
-
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
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
| /* 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