Timer only working for a second
i working on automated pool controller , having problem whenever timer triggered turns on pump second , turns if off. have guidance have done wrong.
code: [select]
#include <time.h>
#include <timealarms.h>
int led = 13;
const int amsw = 2;
int pump = 4;
int ssrctrl = 11;
const int remote = 5;
const int remote2 = 6;
int pumpstate = low;
int buttonstate = 0;
int remotestate = 0;
int remote2state = 0;
int amstate = 0;
int fan = 9;
int estop = 13;
int pumpdet = 10;
int pumpdetstate = 0;
int estopstate = low;
int lastremotestate = low;
long lastdebouncetime = 0;
long debouncedelay = 50;
int ssrstate = 0;
void setup() {
serial.begin(9600);
settime(11,59,50,6,17,14);
pinmode(amsw, input);
pinmode(remote, input);
pinmode(remote2, input);
pinmode(estop, input);
pinmode(led, output);
pinmode(fan, output);
pinmode(pump, output);
pinmode(pumpdet, input);
pinmode(ssrctrl, output);
alarm.alarmrepeat(12,0,0,test);
alarm.alarmrepeat(14,0,0,pumpcycleoff);
digitalwrite(ssrctrl, low);
}
void loop() {
buttonstate = digitalread(amsw);
remotestate = digitalread(remote);
int reading = digitalread(remote);
remote2state = digitalread(remote2);
pumpdetstate = digitalread(pumpdet);
if (buttonstate == high) {
analogwrite(fan, 100);
if (remotestate == high) {
digitalwrite(pump, high);
digitalwrite(ssrctrl, low);
}
if (remote2state == high) {
digitalwrite(pump, low);
digitalwrite(ssrctrl, high);
}
if (pumpdetstate == high) {
analogwrite(fan, 255); }
}
else {digitalwrite(pump, low);
digitalwrite(ssrctrl, high);
analogwrite(fan, 0);
}
digitalclockdisplay();
alarm.delay(1000); // wait 1 second between clock display
}
//these timer controls, leave them set for
//specific jobs.
void test(){
if(buttonstate == low){
digitalwrite(pump, high);
analogwrite(fan, 255);
digitalwrite(ssrctrl, low);
}}
void pumpcycleoff(){
digitalwrite(pump, low);
analogwrite(fan, 90);
digitalwrite(ssrctrl, high);
delay(5000);
analogwrite(fan, 0);}
void digitalclockdisplay()
{
// digital clock display of time
serial.print(hour());
printdigits(minute());
printdigits(second());
serial.println();
}
void printdigits(int digits)
{
serial.print(":");
if(digits < 10)
serial.print('0');
serial.print(digits);
}
code: [select]
void test(){
if(buttonstate == low){
digitalwrite(pump, high);
analogwrite(fan, 255);
digitalwrite(ssrctrl, low);
}}
rubbish. conceivable reason putting 2 curly braces on 1 line save vertical space. after 3 blank lines stupid.
isyourspacebarbroken? if insist on putting { on same line statement, @ least put space in front of it, can seen.
Arduino Forum > Using Arduino > Programming Questions > Timer only working for a second
arduino
Comments
Post a Comment