Code for Fan
//To set up the fan for blowing the scent at a certain time after the essential oil is heated
//Set up pins
int buttonPin = D3;
int fanPin = D2;
//This maintains the state of the button
int buttonLevel = 0;
//Keep the time of when the button was pressed for duration references
long startedAt = 0;
int pressed = 0;
void setup() {
pinMode (fanPin, OUTPUT);
pinMode (buttonPin, INPUT_PULLUP);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState==LOW) {
startedAt = millis();
pressed = 1;
}
else{
}
delay(100);
if ((pressed == 1) && (startedAt + 10000 < millis())){
digitalWrite(fanPin, HIGH);
delay(5000);
digitalWrite(fanPin, LOW);
pressed = 0;
}
else{
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .