|
||
0
0
°ÅÀÇÈ«¸íº¸
¾ÖÃÊ¿¡ ÄÚµùÀ¸·Î ¾ÈµÇ´Â °É±î¿ä..
2017-06-17
|
0
0
¸¶¸®¾ÈÅëÇϳ׶߰¢ÇÏ
ÀÏ´Ü ³í¸®ÀûÀ¸·Î ´Ù½Ã ½áº¸¼¼¿ä
1 5cmÀ̳»·Î ¹°Ã¼°¡ ´Ù°¡¿À¸é ÄÑÁø´Ù 2 ½Ã°£ÀÇ È帧¿¡ µû¶ó Á¡Á¡ ¹à¾ÆÁø´Ù 3 ÄÑÁøÁß¿¡ ´Ù½Ã 5cm·Î ¹°Ã¼°¡ ´Ù°¡¿À¸é ²¨Áø´Ù ÀÌ°ÅÁö¿ä? ŸÀ̸Ӹ¦ »ç¿ëÇÒ¼öÀÖÀ¸¸é Settimer ¿Í killtimer¸¦ ÀÌ¿ëÇϽøéµÇ°í ¾øÀ¸¸é ¸¸µå¼Å¾ßÇÕ´Ï´Ù with for¹® ±×¸®°í state »óŸ¦ ^¸¦ÀÌ¿äÇÏ¿© ¹ÝÀüÇϸéµË´Ï´Ù Áö±ÝÀº 5cm À̳»µé¾î¿À¸é ¹«Á¶°Ç high·ÎµÇ¾î ¹«Á¶°Ç onµÊ ¼ú¸¶¼Å¼ ´õÀ̻󼳸íÀº »ý·«ÇÒ²²¿ä |
0
0
°ÅÀÇÈ«¸íº¸
#define TRIG_PIN 2
#define ECHO_PIN 3 #define LED_PIN 4 #define LED_PIN1 5 #define LED_PIN2 6 // byte state; // unsigned long prev_time=0,current_time,sec; unsigned int distance,cnt=0; void setup() { state = LOW; pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN1, OUTPUT); pinMode(LED_PIN2, OUTPUT); Serial.begin(9600); } void loop() { int distance = 0; current_time=millis(); sec=(current_time-prev_time)/1000; Serial.print(sec); Serial.println("sec"); digitalWrite(TRIG_PIN, HIGH); delay(1000); digitalWrite(TRIG_PIN, LOW); distance = pulseIn(ECHO_PIN, HIGH)/58.2; Serial.print(distance); Serial.println("cm"); if (distance <= 5 ) { if(state == HIGH){ state = LOW; digitalWrite(LED_PIN, LOW); digitalWrite(LED_PIN1, LOW); digitalWrite(LED_PIN2, LOW); } else{ state = HIGH; if(sec<=30){ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, LOW); digitalWrite(LED_PIN2, LOW); } else if(sec<=60){ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, HIGH); digitalWrite(LED_PIN2, LOW); } else{ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, HIGH); digitalWrite(LED_PIN2, HIGH); } } } } ÇöÀç ŸÀÌ¸Ó ÀÌ¿ëÇؼ ®´Âµ¥.. ¿¹¸¦µé¾î óÀ½ ų ¶© LED1¸¸ ÄÑÁö°í ÄÑÁø »óÅ¿¡¼ 30ÃÊ°¡ Áö³ª¸é LED2°¡ ÄÑÁö°í ²¨Áø »óÅ¿¡¼ 60ÃÊ°¡ Áö³ª¸é LED3ÀÌ ²¨Áö°Ô ÇØ¾ß Çϴµ¥.. Áö±Ý ÄÚµå·Î´Â ½Ã°£ÀÌ Áö³ªµµ ÀÚµ¿À¸·Î ÄÑÁöÁø ¾Ê³×¿ä... ¤Ì¤Ì #define TRIG_PIN 2 #define ECHO_PIN 3 #define LED_PIN 4 #define LED_PIN1 5 #define LED_PIN2 6 // byte state; // unsigned long prev_time=0,current_time,sec; unsigned int distance,cnt=0; void setup() { state = LOW; pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN1, OUTPUT); pinMode(LED_PIN2, OUTPUT); Serial.begin(9600); } void loop() { int distance = 0; current_time=millis(); sec=(current_time-prev_time)/1000; Serial.print(sec); Serial.println("sec"); digitalWrite(TRIG_PIN, HIGH); delay(1000); digitalWrite(TRIG_PIN, LOW); distance = pulseIn(ECHO_PIN, HIGH)/58.2; Serial.print(distance); Serial.println("cm"); if (distance <= 5 ) { if(state == HIGH){ state = LOW; digitalWrite(LED_PIN, LOW); digitalWrite(LED_PIN1, LOW); digitalWrite(LED_PIN2, LOW); } else{ state = HIGH; if(sec<=30){ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, LOW); digitalWrite(LED_PIN2, LOW); } else if(sec<=60){ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, HIGH); digitalWrite(LED_PIN2, LOW); } else{ digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN1, HIGH); digitalWrite(LED_PIN2, HIGH); } } } } |
0
0
°ÅÀÇÈ«¸íº¸
¾Æ µÆ³×¿ä °¨»çÇÕ´Ï´Ù
|
|
|
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û | ¸ñ·Ïº¸±â |