Browse Source

done project

master
AHN_SEONG_GEUN 5 years ago
commit
40c2b96e44
  1. 6
      README.md
  2. 27
      project/flag.h
  3. 80
      project/project.ino
  4. 31
      project/pulse.h
  5. 22
      project/steam.h
  6. 22
      project/timer.h

6
README.md

@ -0,0 +1,6 @@
<h1 align="center">기업연계 프로젝트2 팀명:소도기</h1>
<h3 align="center">15조 프로젝트 소스코드</h3>
<h3 align="left">Languages and Tools:</h3>
<p align="left"> <a href="https://www.arduino.cc/" target="_blank"> <img src="https://cdn.worldvectorlogo.com/logos/arduino-1.svg" alt="arduino" width="40" height="40"/> </a> <a href="https://www.w3schools.com/cpp/" target="_blank"> <img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/cplusplus/cplusplus-original.svg" alt="cplusplus" width="40" height="40"/> </a> </p>

27
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<int>(PulseCatch)] = val;
}
inline bool Get(Index index) {
return flag[static_cast<int>(index)];
}
};
#endif

80
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;
}
}

31
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

22
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

22
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
Loading…
Cancel
Save