기업연계 프로젝트2 15조 팀명: 소도기
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

5 years ago
  1. #include "pulse.h"
  2. #include "steam.h"
  3. //#include "flag.h"
  4. //#include "timer.h"
  5. //#define __DEBUG
  6. const int trgiPin = 10;
  7. const int echoPin = 11;
  8. const int steamOnOffPin = 8;
  9. Pulse *pulse;
  10. Steam *steam;
  11. //Flag *flag;
  12. //Timer *timer;
  13. void setup()
  14. {
  15. #ifdef __DEBUG
  16. Serial.begin(9600); // 시리얼 모니터를 사용하기 위해 보드레이트를 9600으로 설정합니다.
  17. #endif
  18. pulse = new Pulse(trgiPin,echoPin);
  19. steam = new Steam(steamOnOffPin);
  20. //flag = new Flag();
  21. //timer = new Timer();
  22. }
  23. void loop()
  24. {
  25. controll();
  26. update();
  27. }
  28. long distance;
  29. void controll() {
  30. pulse->Trig();
  31. long duration = pulse->Echo();
  32. distance = duration * 17 / 1000; // duration을 연산하여 센싱한 거리값을 distance에 저장합니다.
  33. #ifdef __DEBUG
  34. if (distance >= 200 || distance <= 0) // 거리가 200cm가 넘거나 0보다 작으면
  35. {
  36. Serial.println("거리를 측정할 수 없음"); // 에러를 출력합니다.
  37. }
  38. else // 거리가 200cm가 넘지 않거나 0보다 작지 않으면
  39. {
  40. Serial.print(distance); // distance를 시리얼 모니터에 출력합니다.
  41. Serial.println(" cm"); // cm를 출력하고 줄을 넘깁니다.
  42. // distance가 10이면 10 cm로 출력됩니다.
  43. }
  44. delay(500);
  45. #endif
  46. /*if(flag->Get(Index::SteamOn)) {
  47. steam->On();
  48. delay(100);
  49. steam->Off();
  50. flag->Set(Index::SteamOn,false);
  51. flag->Set(Index::TimerOn,false);
  52. }*/
  53. }
  54. bool isCatched = false;
  55. void update() {
  56. if (distance <= 35){
  57. isCatched = true;
  58. }else if(distance >35 && isCatched) {
  59. delay(4000);
  60. steam->On();
  61. delay(3000);
  62. steam->Off();
  63. isCatched = false;
  64. }
  65. }