-
-
Save neosarchizo/a2eb5a63eedc63514753 to your computer and use it in GitHub Desktop.
[아두이노, 상상을 현실로 만드는 프로젝트 입문편] 코드 12 - 2
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 digit = 0; | |
byte digits[10][7] = | |
{ | |
{ 0, 0, 0, 0, 0, 0, 1 }, // 0 | |
{ 1, 0, 0, 1, 1, 1, 1 }, // 1 | |
{ 0, 0, 1, 0, 0, 1, 0 }, // 2 | |
{ 0, 0, 0, 0, 1, 1, 0 }, // 3 | |
{ 1, 0, 0, 1, 1, 0, 0 }, // 4 | |
{ 0, 1, 0, 0, 1, 0, 0 }, // 5 | |
{ 0, 1, 0, 0, 0, 0, 0 }, // 6 | |
{ 0, 0, 0, 1, 1, 1, 1 }, // 7 | |
{ 0, 0, 0, 0, 0, 0, 0 }, // 8 | |
{ 0, 0, 0, 1, 1, 0, 0 } // 9 | |
}; | |
void setup() { | |
pinMode(11, INPUT); | |
pinMode(12, INPUT); | |
for (int i = 2; i < 10; i++) { | |
pinMode(i, OUTPUT); | |
} | |
digitalWrite(9, HIGH); | |
} | |
void loop() { | |
if (digitalRead(11) == HIGH) { | |
++digit; | |
if (digit > 9) { | |
digit = 0; | |
} | |
} | |
if (digitalRead(12) == HIGH) { | |
--digit; | |
if (digit < 0) { | |
digit = 9; | |
} | |
} | |
displayDigit(digit); | |
delay(200); | |
} | |
void displayDigit(int num) { | |
int pin = 2; | |
for (int i = 0; i < 7; i++) { | |
digitalWrite(pin + i, digits[num][i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment