์์ ๋ ์ง ์ฝ๋์ ๋๋ค.
์ดํ์ ์์ ์ ์ ๋ฆฌํ ์๊ฐ์ด ์๋ค....
3.1
SWITCH : ์ค์์น๊ฐ ๊ทธ๋๋ก ์์๋ ON ์ํ์.
define ์ผ๋ก ์ ์๋ฅผ ๋ด๋ฆด ์ ์์;
๋ฐ๋ผ์, const ์ฌ์ฉํด์ผํจ.
delay ์จ์ผํ๋ ์ด์
๋ฌธ์ 3.2
/*
* ๋ฌธ์ 3.2
* Title : ์ค์์น ๋๋ ์๋ RED,GREEN,YELLOW ๊ฐ๊ฐ์ LED๊ฐ ์ผ์ง๋ ๋์
* SWITCH๋ Pull down์ผ๋ก ๊ตฌ์ฑํ์ฌ, ๋๋ ์ ๋ 5V, ์ ๋๋ ธ์ ๋ 0V ๋ก ๊ตฌ์ฑํ๊ฒํ๋ค.
* 2
* Author: james
*/
const int RED_LED = 13;
const int GREEN_LED = 12;
const int YELLOW_LED = 8;
const int R_pinBtn = 7;
const int G_pinBtn = 4;
const int Y_pinBtn = 2;
int R_stateBtn = LOW;
int G_stateBtn = LOW;
int Y_stateBtn = LOW;
void setup()
{
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
pinMode(R_pinBtn, INPUT);
pinMode(G_pinBtn, INPUT);
pinMode(Y_pinBtn, INPUT);
}
void loop()
{
R_stateBtn = digitalRead(R_pinBtn);
G_stateBtn = digitalRead(G_pinBtn);
Y_stateBtn = digitalRead(Y_pinBtn);
if(R_stateBtn == HIGH){
digitalWrite(RED_LED, HIGH);
delay(100);
}
else{
digitalWrite(RED_LED, LOW);
delay(100);
}
if(G_stateBtn == HIGH){
digitalWrite(GREEN_LED, HIGH);
delay(100);
}
else{
digitalWrite(GREEN_LED, LOW);
delay(100);
}
if(Y_stateBtn == HIGH){
digitalWrite(YELLOW_LED, HIGH);
delay(100);
}
else{
digitalWrite(YELLOW_LED, LOW);
delay(100);
}
}
// if else ๋ฌธ์ ๋ํด ์๊ฒ ๋จ.
delay์ ์ ์ฉ์ ๋ํด์ ์๊ฒ๋จ.
/*
* ๋ฌธ์ 4.1
* Title : Rotary PotentionMeter ๋ฅผ ์ด์ฉํ์ฌ, ๋ณํ๋ ์ ํญ๊ฐ์ ๋ฐ๋ฅธ 5๊ฐ์ LED ์ ๋ฑ์ ์ผ์ชฝ๋ถํฐ ๊ตฌํํ๊ธฐ.
*
*
* Author: james
*/
const int LED1 = 12;
const int LED2 = 11;
const int LED3 = 10;
const int LED4 = 9;
const int LED5 = 8;
const int pinPtn = A0;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(pinPtn, INPUT);
}
void loop()
{
float value = 0;
value = analogRead(pinPtn);
int stage1 = 1023/5;
int stage2 = 1023/5*2;
int stage3 = 1023/5*3;
int stage4 = 1023/5*4;
int stage5 = 1023;
if(value >= stage1 ){
digitalWrite(LED1, HIGH);
delay(100);
}
else{
digitalWrite(LED1, LOW);
delay(100);
}
if(value >= stage2 ){
digitalWrite(LED2, HIGH);
delay(100);
}
else{
digitalWrite(LED2, LOW);
delay(100);
}
if(value >= stage3 ){
digitalWrite(LED3, HIGH);
delay(100);
}
else{
digitalWrite(LED3, LOW);
delay(100);
}
if(value >= stage4 ){
digitalWrite(LED4, HIGH);
delay(100);
}
else{
digitalWrite(LED4, LOW);
delay(100);
}
if(value == stage5 ){
digitalWrite(LED5, HIGH);
delay(100);
}
else{
digitalWrite(LED5, LOW);
delay(100);
}
}
/*
* ๋ฌธ์ 4.2
* Title : ์กฐ๋ ์ผ์ ๋ฅผ ์ด์ฉํ์ฌ, ๋ณํ๋ ์ ํญ๊ฐ์ ๋ฐ๋ฅธ 5๊ฐ์ LED ์ ๋ฑ์ ๊ตฌํํ๊ธฐ.
* ์กฐ๋ ์ผ์์ ์ฐ๊ฒฐ๋๋ ์ง๋ ฌ ์ ํญ์ 10k ์ฌ์ฉํด์ผ, 500๊ฐ์์ ์กฐ๋ ๊ฐ์ ์ ๋ฐ์ํด์ ์ผ์์ RANGE ํ๋ณด ๊ฐ๋ฅํ๋ค.
*
* Author: james
*/
const int LED1 = 12;
const int LED2 = 11;
const int LED3 = 10;
const int LED4 = 9;
const int LED5 = 8;
const int pinCds = A0;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(pinCds, INPUT);
}
void loop()
{
float value = 0;
value = analogRead(pinCds);
int stage1 = 500;
if(value <= stage1 ){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
delay(100);
}
else{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
}
}
/*
* ๋ฌธ์ 4.3
* Title : ์จ๋๊ฐ 30๋ ์ด์์ด๋ฉด LED์ Active Buzzer๊ฐ ๋์
* ์จ๋ ๊ณต์์ด ํ์ํ๋ค.
*
* Author: james
*/
const int LED1 = 12;
const int LED2 = 11;
const int LED3 = 10;
const int LED4 = 9;
const int LED5 = 8;
const int pinBzr = 4;
const int pinLM35 = A0;
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(pinLM35, INPUT);
pinMode(pinBzr, OUTPUT);
}
void loop()
{
float value, voltage, temperature = 0;
value = analogRead(pinLM35);
voltage = value/1023*5;
temperature = voltage*100;
int boundary_temp = 30;
if(value >= boundary_temp ){
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
digitalWrite(pinBzr, HIGH);
delay(100);
}
else{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(pinBzr, LOW);
delay(100);
}
}
'๐ฅ๊ณต๋์ด๊ฑฐ์ ๊ฒ(๋งํ๊ธฐ) > ๐บ๋ง์ดํฌ๋กํ๋ก์ธ์์ค์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋์ด๋ ธ ๋ณด๋ ํ ์ค๋ช (0) | 2020.09.25 |
---|---|
LCDํจ๋ (0) | 2020.09.19 |
์ด์ํ์ผ์ (0) | 2020.09.19 |