#include "pulse.h" #include "steam.h" //#include "flag.h" //#include "timer.h" //#define __DEBUG const int trgiPin = 10; const int echoPin = 11; const int steamOnOffPin = 8; Pulse *pulse; Steam *steam; //Flag *flag; //Timer *timer; void setup() { #ifdef __DEBUG Serial.begin(9600); // 시리얼 모니터를 사용하기 위해 보드레이트를 9600으로 설정합니다. #endif pulse = new Pulse(trgiPin,echoPin); steam = new Steam(steamOnOffPin); //flag = new Flag(); //timer = new Timer(); } void loop() { controll(); update(); } long distance; void controll() { pulse->Trig(); long duration = pulse->Echo(); distance = duration * 17 / 1000; // duration을 연산하여 센싱한 거리값을 distance에 저장합니다. #ifdef __DEBUG if (distance >= 200 || distance <= 0) // 거리가 200cm가 넘거나 0보다 작으면 { Serial.println("거리를 측정할 수 없음"); // 에러를 출력합니다. } else // 거리가 200cm가 넘지 않거나 0보다 작지 않으면 { Serial.print(distance); // distance를 시리얼 모니터에 출력합니다. Serial.println(" cm"); // cm를 출력하고 줄을 넘깁니다. // distance가 10이면 10 cm로 출력됩니다. } delay(500); #endif /*if(flag->Get(Index::SteamOn)) { steam->On(); delay(100); steam->Off(); flag->Set(Index::SteamOn,false); flag->Set(Index::TimerOn,false); }*/ } bool isCatched = false; void update() { if (distance <= 35){ isCatched = true; }else if(distance >35 && isCatched) { delay(4000); steam->On(); delay(3000); steam->Off(); isCatched = false; } }