Hi Guys,
I ran my project last night and it worked great. I then went to bed and as my head hit the pillow i realized…
If my power goes out and comes back on my program will restart and destroy my distiller.
I found and have working some code that allows me to press a button to start my PWM but it seems the button code stops my loop from running (Unless i press it again)
Can someone show me how to handle this?
I would like to press the momentary button once and then program runs like without the button code.
#include "TimerOne.h"
#include <Button.h>
unsigned long time;
//unsigned long Cutout = 16800000;
unsigned long Cutout = 30000;
unsigned long Fan = 20000;
Button button = Button(12,PULLUP);
const int fanrelay = 13;
int duty = 614;
void setup()
{
pinMode(9, OUTPUT);
pinMode(fanrelay, OUTPUT);
Timer1.initialize(500000); // initialize timer1, and set a 1 second period
//Serial.begin(9600);
}
void loop()
{
if(button.uniquePress()){//button.isPressed() will cause the code to execute as long as button is pressed}
if (time >= Fan)
digitalWrite(fanrelay, HIGH);
time = millis();
Timer1.pwm(9,duty); // setup pwm on pin 9, 0-1024 max resolution /100*% to get a % duty eg; 614.4 is 60%
if (time >= Cutout)
//duty = 100;
//Serial.print("time = ");
// Serial.print(time);
// Serial.print(" duty = ");
// Serial.println(duty);
//if (time >= Cutout2)
shutdown();
//delay (1000);
}
}
void shutdown()
{
// add you emergency shutdown code here
Timer1.disablePwm(9);
while(1); // endless loop
}