Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. int const startPin = 13; // ガスクロ
  2. int previousHour = -1;
  3. const long oneHour = 3600000; // 1 h = 360000 ms
  4. const long oneMinute = 60000; // 1 min = 60000 ms
  5. const long oneSecond = 1000; // 1 s = 1000 ms
  6.  
  7. int const pinOpen = 7; // 電磁弁OPEN
  8. int const pinClose = 8; // 電磁弁CLOSE
  9. int initialize = 0; // 初期化
  10. void setup() {
  11. Serial.begin(9600);
  12. // startpinの初期化 ここでクロマトパックがSTART
  13. pinMode(startPin, OUTPUT);
  14. pinMode(pinClose, OUTPUT);
  15. delay(1500);
  16. }
  17.  
  18. void loop() {
  19. if (initialize == 0) {
  20. // 初期化:電磁弁クローズにする.
  21. closeValve();
  22. initialize = 1;
  23. }
  24.  
  25. // 前のループよりも今のHourが大きければ,GCをSTART = 1時間経過したか?
  26. if (hour() > previousHour) {
  27. valve(); // バルブをひねって戻す
  28. startGC(); // ガスクロ
  29. previousHour += 1; // 次のループのためにincrement
  30. } else {
  31. formatTime(); // 経過時間表示+delay
  32. delay(1000);
  33. }
  34. }
  35.  
  36. void valve() {
  37. openValve();
  38. closeValve();
  39. }
  40.  
  41. void openValve() {
  42. digitalWrite(pinOpen, HIGH);
  43. delay(5000);
  44. digitalWrite(pinOpen, LOW);
  45. delay(55000);
  46. }
  47.  
  48. void closeValve() {
  49. digitalWrite(pinClose, HIGH);
  50. delay(5000);
  51. digitalWrite(pinClose, LOW);
  52. delay(2000);
  53. }
  54.  
  55. void startGC() {
  56. digitalWrite(startPin, HIGH);
  57. Serial.println("start");
  58. delay(500);
  59. digitalWrite(startPin, LOW);
  60.  
  61. }
  62.  
  63. void formatTime() {
  64. if (hour() > 0) {
  65. Serial.print(hour());
  66. Serial.print("h");
  67. Serial.print(minute());
  68. Serial.print("m");
  69. Serial.print(second());
  70. Serial.println("s");
  71. } else if (minute() > 0) {
  72. Serial.print("0h");
  73. Serial.print(minute());
  74. Serial.print("m");
  75. Serial.print(second());
  76. Serial.println("s");
  77. } else {
  78. Serial.print("0m");
  79. Serial.print(second());
  80. Serial.println("s");
  81. }
  82. }
  83.  
  84. int hour() {
  85. return millis() / oneHour;
  86. }
  87.  
  88. int minute() {
  89. return millis() / oneMinute - (60 * hour());
  90. }
  91.  
  92. int second() {
  93. return millis() / oneSecond - (3600 * hour()) - (60 * minute());
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement