Viking Skull Lamp  V1.0.1
Loading...
Searching...
No Matches
fogMachine.cpp
Go to the documentation of this file.
1/*
2 * Created on May 28 2022
3 *
4 * Copyright (c) 2022 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Viking Skull Lamp project.
7 * Modified 2022.06.27
8*/
9
10/*
11MIT License
12Copyright (c) 2022 Daniel Hajnal
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27SOFTWARE.
28*/
29
30#include "fogMachine.hpp"
31
35unsigned long fogMachineTimer = 0;
36
39unsigned long fogLastTurnOn = 0;
40
45unsigned long fogCoolDownTimer = 0;
46
48bool fogCoolDown = false;
49
51
52 pinMode( HUMIDIFIER_PIN, OUTPUT );
53 digitalWrite( HUMIDIFIER_PIN, 0 );
54
55}
56
58
59 // Calculate one minute in ms.
60 unsigned long timerCalculated = (unsigned long)1000 * 60; // one minute
61
62 // Check if the maximum allowed on time has expired.
63 if( ( ( (unsigned long)millis() - fogLastTurnOn ) > HUMIDIFIER_DURATION ) ){
64
65 // If the humidifier is turned of we have to turn if off.
66 if( digitalRead( HUMIDIFIER_PIN ) ){
67
68 digitalWrite( HUMIDIFIER_PIN, 0 );
69 Serial.print( millis() );
70 Serial.print( F( " : " ) );
71 Serial.println( F( "Humidifier finished! Cool-down timer start..." ) );
72
73 // Start the cool down procedure by setting
74 // the flag and saving the system time.
75 fogCoolDown = true;
76 fogCoolDownTimer = millis();
77
78 }
79
80 }
81
82 // Check if the cool down period expired.
83 if( fogCoolDown && ( ( (unsigned long)millis() - fogCoolDownTimer ) > HUMIDIFIER_COOL_DOWN ) ){
84
85 Serial.print( millis() );
86 Serial.print( F( " : " ) );
87 Serial.println( F( "Cooling finished!" ) );
88
89 // If the cool down procedure finished,
90 // clear the flag.
91 fogCoolDown = false;
92
93 }
94
95 // In this section we just calculate the automatic humidification
96 // periods based on the fogTimer variable.
97 switch( fogTimer ){
98
99 case 0:
100 timerCalculated = (unsigned long)15 * timerCalculated;
101 break;
102
103 case 1:
104 timerCalculated = (unsigned long)30 * timerCalculated;
105 break;
106
107 case 2:
108 timerCalculated = (unsigned long)45 * timerCalculated;
109 break;
110
111 case 3:
112 timerCalculated = (unsigned long)60 * timerCalculated;
113 break;
114
115 case 4:
116 timerCalculated = (unsigned long)90 * timerCalculated;
117 break;
118
119 case 5:
120 timerCalculated = (unsigned long)120 * timerCalculated;
121 break;
122
123 case 6:
124 timerCalculated = (unsigned long)180 * timerCalculated;
125 break;
126
127 case 7:
128 timerCalculated = (unsigned long)300 * timerCalculated;
129 break;
130
131 case 8:
132 timerCalculated = (unsigned long)480 * timerCalculated;
133 break;
134
135 case 9:
136 timerCalculated = (unsigned long)720 * timerCalculated;
137 break;
138
139 case 10:
140 timerCalculated = (unsigned long)1440 * timerCalculated;
141 break;
142
143 default:
144
145 return;
146
147 break;
148
149 }
150
151 // Check if the automatic humidification has to be turned on.
152 if( ( (unsigned long)millis() - fogMachineTimer ) > timerCalculated ){
153
154 // Save the system time for the logic.
155 fogMachineTimer = millis();
156
157 // Try to enable the humidifier.
159 Serial.print( millis() );
160 Serial.print( F( " : " ) );
161 Serial.println( F( "Timer elapsed, humidifier turning on..." ) );
162
163 }
164
165}
166
168
169 // If the humidifier is disabled we are not allowed to turn it on.
170 if( !fogMachineEnabled ){
171
172 return;
173
174 }
175
176 // If the humidifier pin is off and the cool down procedure
177 // expired, we are allowed to turn on the humidifier.
178 if( !digitalRead( HUMIDIFIER_PIN ) && !fogCoolDown ){
179
180 // Save the system time for the logic.
181 fogLastTurnOn = millis();
182 digitalWrite( HUMIDIFIER_PIN, 1 );
183
184 }
185
186}
unsigned long fogCoolDownTimer
This variable stores the last system time when the cool down event happened.
Definition: fogMachine.cpp:45
unsigned long fogMachineTimer
This variable is used for automatic humidification.
Definition: fogMachine.cpp:35
void fogMachineEnable()
Enable the humidifier.
Definition: fogMachine.cpp:167
void fogMachineInit()
Initialize the fog machine( humidifier ).
Definition: fogMachine.cpp:50
bool fogCoolDown
If the cool down procedure still in progress, this flag will be true.
Definition: fogMachine.cpp:48
unsigned long fogLastTurnOn
This variable stores the last system time when the humidifier was turned on by any reason.
Definition: fogMachine.cpp:39
void fogMachineUpdate()
Update the fog machine state.
Definition: fogMachine.cpp:57
#define HUMIDIFIER_DURATION
Humidifier turn on duration in ms. The humidifier will be turned on for this amount of time.
Definition: fogMachine.hpp:41
#define HUMIDIFIER_PIN
The humidifier is connected to pin 6 on the Arduino.
Definition: fogMachine.hpp:38
#define HUMIDIFIER_COOL_DOWN
Humidifier cool down time. The humidifier has to be turned off for this amount of time before turning...
Definition: fogMachine.hpp:44
bool fogMachineEnabled
It will store the user selected state of the fog machine.
Definition: menu.cpp:54
uint8_t fogTimer
It will store the user selected humidification period.
Definition: menu.cpp:56