GPIO ๋ฐ ์ธ๋ถ LED ๊ตฌํ
1. ํ์ต ๋ชฉํ
1-1. ESP32์์ GPIO ์ฌ์ฉ
2. GPIO ์ ์
2-1. ๋ค์ฉ๋ ์
์ถ๋ ฅ(General Purpose Input/Output)
2-2. ์
/์ถ๋ ฅ ๋์์ด ์ฌ์ฉ์์ ์ํด ์ ์ด๋๋ ์ง์ ํ๋ก or ์ ๊ธฐ ํ๋ก ๊ธฐํ์ ๋์งํธ ์ ํธํ
2-3. ์ด์
๋ธ๋ฆฌ ๋ ๋ฒจ์ ํ๋ก๋ง ์ค๊ณ์์ ์ํด ๊ตฌํ๋จ
3. ์ธ๋ถ LED ์ค์ต 1
- ์ธ๋ถ LED ์ผ๊ณ ๋๊ธฐ(๋์งํธ ์ถ๋ ฅ)
- ์ค๋น๋ฌผ: ESP32, ESP32 ํ์ฅ ์ค๋, LED ๋ชจ๋, ์ ํผ ์ผ์ด๋ธ 3๊ฐ
const int ledPin = 4; //led ํ ๋ฒํธ ์ค์
//setupํจ์๋ ๋ฆฌ์
์ ๋๋ฅด๊ฑฐ๋ ๋ณด๋์ ์ ์์ ๊ณต๊ธํ ๋ ํ ๋ฒ ์คํ
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
4. ์ธ๋ถ LED ์ค์ต 2
- ์ธ๋ถ LED ์ผ๊ณ ๋๊ธฐ(์๋ ๋ก๊ทธ ์ถ๋ ฅ)
- ์ค๋น๋ฌผ: ESP32, ESP32 ํ์ฅ ์ค๋, LED ๋ชจ๋, ์ ํผ ์ผ์ด๋ธ 3๊ฐ
const int ledPin = 4;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
for(int i = 0; i <= 255; i++) {
analogWrite(ledPin, i);
delay(15);
}
for(int i = 255; i >= 0; i--){
analogWrite(ledPin, i);
delay(15);
}
}
5. ์ธ๋ถ LED ์ค์ต 3
- ์ธ๋ถ LED ์ผ๊ณ ๋๊ธฐ(๋์งํธ ์
๋ ฅ, ๋ฒํผ ์ฌ์ฉ)
- ์ค๋น๋ฌผ: ESP32, ESP32 ํ์ฅ ์ค๋, LED ๋ชจ๋, ๋ฒํผ ๋ชจ๋, ์ ํผ ์ผ์ด๋ธ 6๊ฐ
const int buttonPin = 33;
const int ledPin = 4;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if(buttonState == LOW) {
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}
6. ์ธ๋ถ LED ์ค์ต 4
- ์ธ๋ถ LED ์ผ๊ณ ๋๊ธฐ(์๋ ๋ก๊ทธ ์
๋ ฅ, ๊ฐ๋ณ ์ ํญ)
- ์ค๋น๋ฌผ: ESP32, ESP32 ํ์ฅ ์ค๋, LED ๋ชจ๋, ๊ฐ๋ณ ์ ๋ชจ๋, ์ ํผ ์ผ์ด๋ธ 6๊ฐ
const int potPin = 34;
const int ledPin = 4;
int potValue = 0;
void setup() {
// put your setup code here, to run once:
pinMode(potPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
potValue = analogRead(potPin);
analogWrite(ledPin, map(potValue, 0, 4095, 0, 255));
delay(500);
}
7. ๋ถ๊ฐ์ค๋ช
โ ESP32 ์นฉ์ ๋ค์ํ ๊ธฐ๋ฅ์ ๊ฐ์ง 48ํ๊ณผ ํจ๊ป ์ ๊ณต๋๋ฉฐ ์๋์ด๋
ธ์ ์ฌ์ฉ๋ฒ์ด ๊ฐ์
โ ESP Devkit: EN, VIN, 3V3, GND ๋ฐ ์
๋ ฅ ์ ์ฉํ(34,35,36,39)๋ฅผ ์ ์ธํ ๋ชจ๋ ํ์ ๋์งํธ ์ถ๋ ฅ์ ์ฌ์ฉ ๊ฐ๋ฅํจ
โ ๊ทธ๋ผ์ด๋(GND)๊ฐ ๋ง์ผ๋ฉด ์์ ์ ์ผ๋ก ๋์๊ฐ
โ UART(Universal Asynchronous Receiver/Transmitter): ๋ ์ฅ์น ๊ฐ์ ์ง๋ ฌ ๋ฐ์ดํฐ๋ฅผ ๊ตํํ๋ฉฐ ๋๊ฐ์ ์ ์ ์ผ๋ก ํต์ ํ ์ ์์ด ๊ฐ์ฅ ๊ฐ๋จํ ํต์ ํ๋กํ ์ฝ ์ค ํ๋์
โ DAC: ๋์งํธ ์๋ ๋ก๊ทธ ๋ณํ ํ๋ก(์๊ฐ ์๋ฃ ํ์ฉ์ ์ํด ํจ๋ ์์ฒด ํ์์ ๋ฐ๊ธฐ๋ฅผ ์ ์ดํจ)
โ ADC: ์๋ ๋ก๊ทธ ๋์งํธ ๋ณํ ํ๋ก์ด๋ฉฐ DAC์ ์ญ๋ฐฉํฅ ์ฒ๋ฆฌ๋ฅผ ์ํ, ์๋ ๋ก๊ทธ ์ ํธ๋ฅผ ๋์งํธ ์ ํธ๋ก ๋ณํํ๋ฉฐ ๋๋ถ๋ถ์ ์ผ์ ๊ธฐ๊ธฐ์ ์ฌ์ฉ๋๋ ํ๋ก
โ TWN: ๋์งํธ ์ถ๋ ฅ(DAC๋ฅผ ์ฌ์ฉํ์ง ์๊ณ LED ๋ฐ๊ธฐ ์กฐ์ ๊ฐ๋ฅ)
โ PWM: ํ์ค ๋ณ์กฐ์ ์ผ์ข
์ด๋ฉฐ ์ ํธ ํฌ๊ธฐ์ ๋ฐ๋ผ ํ์ค์ ํญ์ ๋ณ์กฐํจ(DAC์ ๋ฐ๋๋๋ ๊ฐ๋
์ ๋์งํธ ์ถ๋ ฅ)
8. ์๊ฐ ์๋ฃ
9. ์ฐธ๊ณ ์์