7세그먼트
7세그먼트로 숫자나 문자를 나타낼 수 있다.
하지만 대부분 간단한 숫자를 나타내는데 사용한다.
회로도
복잡하지만 최대한 보기 쉽게 그려놨다.
![](https://blog.kakaocdn.net/dn/bdJbVD/btsEm8kbGuu/QglBhNrdEUoiJp00foYbO0/img.png)
세그먼트 on, off하기
1초마다 세그먼트의 전부가 on, off 하는 코드다.
on을 하면 세그먼트에 8이 나올 것이며 off를 하면 아무것도 나오지 않는다.
#define A_PIN 2
#define DP_PIN 9
void setup()
{
for(int i = A_PIN; i <= DP_PIN; i++) //세그먼트 셋업
pinMode(i, OUTPUT);
}
void loop()
{
OnOff(1);
delay(1000);
OnOff(0);
delay(1000);
}
void OnOff(bool bOn)
{
for(int i=A_PIN; i<=DP_PIN; i++) //전부 끄기 or 켜기
digitalWrite(i, bOn);
}
세그먼트 0 ~ 9 까지 출력하기
1초 간격으로 세그먼트 0 ~ 9 까지 출력
#define A_PIN 2
#define DP_PIN 9
//LED 숫자
#define NUM_0 1,1,1,1,1,1,0
#define NUM_1 0,1,1,0,0,0,0
#define NUM_2 1,1,0,1,1,0,1
#define NUM_3 1,1,1,1,0,0,1
#define NUM_4 0,1,1,0,0,1,1
#define NUM_5 1,0,1,1,0,1,1
#define NUM_6 0,0,1,1,1,1,1
#define NUM_7 1,1,1,0,0,0,0
#define NUM_8 1,1,1,1,1,1,1
#define NUM_9 1,1,1,0,0,1,1
void setup()
{
for(int i=A_PIN; i<=DP_PIN; i++)
pinMode(i, OUTPUT);
}
void loop()
{
DisplayNum(NUM_0);
delay(1000);
DisplayNum(NUM_1);
delay(1000);
DisplayNum(NUM_2);
delay(1000);
DisplayNum(NUM_3);
delay(1000);
DisplayNum(NUM_4);
delay(1000);
DisplayNum(NUM_5);
delay(1000);
DisplayNum(NUM_6);
delay(1000);
DisplayNum(NUM_7);
delay(1000);
DisplayNum(NUM_8);
delay(1000);
DisplayNum(NUM_9);
delay(1000);
}
//LED 0 ~ 9 까지 출력
void DisplayNum(byte a, byte b, byte c, byte d, byte e, byte f, byte g)
{
digitalWrite(A_PIN, a);
digitalWrite(A_PIN+1, b);
digitalWrite(A_PIN+2, c);
digitalWrite(A_PIN+3, d);
digitalWrite(A_PIN+4, e);
digitalWrite(A_PIN+5, f);
digitalWrite(A_PIN+6, g);
}
반응형
'Arduino' 카테고리의 다른 글
[Arduino] 아두이노 가변저항 사용해서 LED 밝기 조절하기 (0) | 2024.02.02 |
---|---|
[Arduino] 아두이노 DC 모터(L298N) 제어하기 (0) | 2024.02.02 |
[Arduino] 아두이노 푸시 버튼으로 LED 제어하기 (0) | 2024.02.02 |
[Arduino] 아두이노 푸시 버튼(push button) 사용하기, INPUT, INPUT_PULLUP (0) | 2024.02.02 |
[Arduino] 아두이노 부저(Buzzer) 능동부저, 수동부저 (0) | 2024.02.02 |