- 준비물
- 7segment 1개
- 버튼스위치 2개
- 10㏀ 저항 2개
- 220Ω 저항 1개
- 코드
int digit = 0;
byte digits[10][7] = {
{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},
{0, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 1, 1},
};
const int minusButtonPin = 2;
const int plusButtonPin = 3;
void setup() {
//pin mode setup
for (int i = 2 ; i < 12 ; i++) {
if (i < 4) {
pinMode(i, INPUT);
}
else {
pinMode(i, OUTPUT);
}
}
//dot pin off
digitalWrite(11, LOW);
}
void loop() {
//push minus button
if (digitalRead(minusButtonPin) == HIGH) {
if (digit == 0) {
digit = 9;
}
else {
digit--;
}
}
//push plus button
else if (digitalRead(plusButtonPin) == HIGH) {
if (digit == 9) {
digit = 0;
}
else {
digit++;
}
}
outputDigit(digit);
delay(200);
}
//output 7segment number
void outputDigit(int digit) {
for (int i = 4 ; i < 11 ; i++) {
for (int j = 0 ; j < 6 ; j++) {
digitalWrite(i, digits[digit][i - 4]);
}
}
}
- 영상