commit 40c2b96e441b7c136206a18bcd195490354da09e Author: AHN_SEONG_GEUN Date: Tue Jun 29 18:32:28 2021 +0900 done project diff --git a/README.md b/README.md new file mode 100644 index 0000000..aeea675 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +

기업연계 프로젝트2 팀명:소도기

+

15조 프로젝트 소스코드

+ + +

Languages and Tools:

+

arduino cplusplus

diff --git a/project/flag.h b/project/flag.h new file mode 100644 index 0000000..5ff4e1e --- /dev/null +++ b/project/flag.h @@ -0,0 +1,27 @@ +#ifndef __FLAG_H_ +#define __FLAG_H_ + +enum Index { + PulseCatch = 0, + TimerOn, + SteamOn, +}; + +class Flag { +private: + bool *flag; +public: + Flag(){ + flag = new bool[2]; + for(int i =0;i< 3;i++) + flag[i] = false; + } + inline void Set(Index index,bool val){ + flag[static_cast(PulseCatch)] = val; + } + inline bool Get(Index index) { + return flag[static_cast(index)]; + } +}; + +#endif diff --git a/project/project.ino b/project/project.ino new file mode 100644 index 0000000..1963715 --- /dev/null +++ b/project/project.ino @@ -0,0 +1,80 @@ +#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; + + } +} + diff --git a/project/pulse.h b/project/pulse.h new file mode 100644 index 0000000..f57f547 --- /dev/null +++ b/project/pulse.h @@ -0,0 +1,31 @@ +#ifndef __PULSE_H_ +#define __PLUSE_H_ + +class Pulse { +private: + int trigPin; + int echoPin; +public: + + Pulse(int t,int e) : trigPin(t),echoPin(e) { + pinMode(t,OUTPUT); + pinMode(e,INPUT); + } + void Trig() { // trigPin에 LOW를 출력하고 + digitalWrite(trigPin, LOW); // trigPin에 LOW를 출력하고 + + delayMicroseconds(2); // 2 마이크로초가 지나면 + + digitalWrite(trigPin, HIGH); // trigPin에 HIGH를 출력합니다. + + delayMicroseconds(10); // trigPin을 10마이크로초 동안 기다렸다가 + + digitalWrite(trigPin, LOW); + } + + unsigned long Echo() { + return pulseIn(echoPin,HIGH); + } + +}; +#endif \ No newline at end of file diff --git a/project/steam.h b/project/steam.h new file mode 100644 index 0000000..23a391a --- /dev/null +++ b/project/steam.h @@ -0,0 +1,22 @@ +#ifndef __STEAM_H_ +#define __STEAM_H_ + +class Steam { +private: + int outputV5; + + + +public: + Steam(int outputPin) : outputV5(outputPin){ + pinMode(outputPin, OUTPUT); + } + void On() { + digitalWrite(outputV5,HIGH); + } + void Off() { + digitalWrite(outputV5,LOW); + } +}; + +#endif \ No newline at end of file diff --git a/project/timer.h b/project/timer.h new file mode 100644 index 0000000..911ec38 --- /dev/null +++ b/project/timer.h @@ -0,0 +1,22 @@ +#ifndef __TIMER_H_ +#define __TIMER_H_ + +class Timer { +private: + unsigned long prev; + unsigned long current; +public: + Timer() { + current = prev = millis(); + } + inline void ChkFirst() { + prev = millis(); + } + inline void ChkLast() { + current = millis(); + } + + unsigned long GetSecond() {return (current - prev) / 1000;} +}; + +#endif \ No newline at end of file