Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int const startPin = 13; // ガスクロ
- int previousHour = -1;
- const long oneHour = 3600000; // 1 h = 360000 ms
- const long oneMinute = 60000; // 1 min = 60000 ms
- const long oneSecond = 1000; // 1 s = 1000 ms
- int const pinOpen = 7; // 電磁弁OPEN
- int const pinClose = 8; // 電磁弁CLOSE
- int initialize = 0; // 初期化
- void setup() {
- Serial.begin(9600);
- // startpinの初期化 ここでクロマトパックがSTART
- pinMode(startPin, OUTPUT);
- pinMode(pinClose, OUTPUT);
- delay(1500);
- }
- void loop() {
- if (initialize == 0) {
- // 初期化:電磁弁クローズにする.
- closeValve();
- initialize = 1;
- }
- // 前のループよりも今のHourが大きければ,GCをSTART = 1時間経過したか?
- if (hour() > previousHour) {
- valve(); // バルブをひねって戻す
- startGC(); // ガスクロ
- previousHour += 1; // 次のループのためにincrement
- } else {
- formatTime(); // 経過時間表示+delay
- delay(1000);
- }
- }
- void valve() {
- openValve();
- closeValve();
- }
- void openValve() {
- digitalWrite(pinOpen, HIGH);
- delay(5000);
- digitalWrite(pinOpen, LOW);
- delay(55000);
- }
- void closeValve() {
- digitalWrite(pinClose, HIGH);
- delay(5000);
- digitalWrite(pinClose, LOW);
- delay(2000);
- }
- void startGC() {
- digitalWrite(startPin, HIGH);
- Serial.println("start");
- delay(500);
- digitalWrite(startPin, LOW);
- }
- void formatTime() {
- if (hour() > 0) {
- Serial.print(hour());
- Serial.print("h");
- Serial.print(minute());
- Serial.print("m");
- Serial.print(second());
- Serial.println("s");
- } else if (minute() > 0) {
- Serial.print("0h");
- Serial.print(minute());
- Serial.print("m");
- Serial.print(second());
- Serial.println("s");
- } else {
- Serial.print("0m");
- Serial.print(second());
- Serial.println("s");
- }
- }
- int hour() {
- return millis() / oneHour;
- }
- int minute() {
- return millis() / oneMinute - (60 * hour());
- }
- int second() {
- return millis() / oneSecond - (3600 * hour()) - (60 * minute());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement