added switch off timer, bug fixes
This commit is contained in:
parent
1d04de4b3c
commit
589de4957a
62
README.md
62
README.md
@ -23,14 +23,15 @@ All functions are controlled by the KY-040 encoder:
|
||||
* **BTIME**: turn sets the boost time in minutes.
|
||||
* **CATCH**: turn activates/deactivates the fishing function
|
||||
* **CTIME**: turn sets the interval in minutes for the fish catching function
|
||||
* **RTIME**: speed rise time in seconds (applys to power on, stirrer on, boost on and fish catching)
|
||||
* **RTIME**: speed rise time in seconds (applies to power on, stirrer on, boost on and fish catching)
|
||||
* **OTIME**: switch stirrer off after time in hours (the timer activates immediately, 0 = switch off disabled)
|
||||
|
||||
## Display Indicators:
|
||||
|
||||
* **Bottom Left**: Menu
|
||||
* **Bottom centre/right**: displays the set values for the stirrers depending on the selected menu item.
|
||||
* **Top Center/Right**: displays the current stirrer speed (or 'OFF' or 'CAT' (Fishing)).
|
||||
* **Top left**: shows the remaining time of the boost function.
|
||||
* **Top left**: shows the remaining time of the boost or switch off function.
|
||||
|
||||
## Settings (in stir.ino)
|
||||
|
||||
@ -70,33 +71,42 @@ Command are colon separated an can be send via USB/Serial
|
||||
|`coff:<0/1>`|switch catch mode off|
|
||||
|`ctime:<0/1>:<min>`|set catch mode interval (60-240 min)|
|
||||
|`rtime:<0/1>:<sec>`|set speed rise time (0-240 sec)|
|
||||
|`otime:<0/1>:<hour>`|switch stirrer off after time in hours (1-99 hour, 0 deactivates switch off)|
|
||||
|
||||
All commands return a colon separated string with all current parameters:
|
||||
|
||||
|Element|Descriptoion|
|
||||
|:------|:-----------|
|
||||
|0|stirrer 0 state|
|
||||
|1|stirrer 0 speed|
|
||||
|2|stirrer 0 boost speed|
|
||||
|3|stirrer 0 rpm|
|
||||
|4|stirrer 0 averaged rpm|
|
||||
|5|stirrer 0 regulation value|
|
||||
|6|stirrer 0 boost time|
|
||||
|7|stirrer 0 fish catch mode state|
|
||||
|8|stirrer 0 fish catch mode time|
|
||||
|9|stirrer 0 speed rise time|
|
||||
|10|stirrer 1 state|
|
||||
|11|stirrer 1 speed|
|
||||
|12|stirrer 1 boost speed|
|
||||
|13|stirrer 1 rpm|
|
||||
|14|stirrer 1 averaged rpm|
|
||||
|15|stirrer 1 regulation value|
|
||||
|16|stirrer 1 boost time|
|
||||
|17|stirrer 1 fish catch mode state|
|
||||
|18|stirrer 1 fish catch mode time|
|
||||
|19|stirrer 1 speed rise time|
|
||||
|20|0=ok, 1=error|
|
||||
|21|software version|
|
||||
|Element|Stirrer|Description|
|
||||
|:------|:------|:-----------|
|
||||
| 0|0|state (0=on, 1=off)|
|
||||
| 1|0|speed (rpm)|
|
||||
| 2|0|boost speed (rpm)|
|
||||
| 3|0|rpm|
|
||||
| 4|0|averaged rpm|
|
||||
| 5|0|regulation value|
|
||||
| 6|0|boost state (0=on, 1=off)|
|
||||
| 7|0|boost time (min)|
|
||||
| 8|0|fish catch mode state (0=on, 1=off)|
|
||||
| 9|0|fish catch time interval (min)|
|
||||
|10|0|speed rise time (sec)|
|
||||
|11|0|switch off time (hour)|
|
||||
|12|0|boost remain (sec)|
|
||||
|13|0|off timer remain (sec)|
|
||||
|14|1|state (0=on, 1=off)|
|
||||
|15|1|speed (rpm)|
|
||||
|16|1|boost speed (rpm)|
|
||||
|17|1|rpm|
|
||||
|18|1|averaged rpm|
|
||||
|19|1|regulation value|
|
||||
|20|1|boost state (0=on, 1=off)|
|
||||
|21|1|boost time (min)|
|
||||
|22|1|fish catch mode state (0=on, 1=off)|
|
||||
|23|1|fish catch time interval (min)|
|
||||
|24|1|speed rise time (sec)|
|
||||
|25|1|switch off time (hour)|
|
||||
|26|1|boost remain (sec)|
|
||||
|27|1|off timer remain (sec)|
|
||||
|28||0=ok, 1=error|
|
||||
|29||software version|
|
||||
|
||||
## Schematics
|
||||
|
||||
|
75
stir.ino
75
stir.ino
@ -7,7 +7,7 @@
|
||||
#define SX Serial.print
|
||||
#define SXN Serial.println
|
||||
|
||||
String VERSION = "1.5.1";
|
||||
String VERSION = "1.5.2";
|
||||
|
||||
int SPEEDINC = 50; // speed increment (rpm)
|
||||
|
||||
@ -33,7 +33,7 @@ int RTOL = 8;
|
||||
long SINTERVAL = 2000; // speed measurement interval
|
||||
int SAVERAGE = 4; // speed measurement average
|
||||
|
||||
int SAVETAG = 1007; // save tag
|
||||
int SAVETAG = 1011; // save tag
|
||||
long SAVEDELAY = 60000; // EEPROM save delay (ms)
|
||||
|
||||
byte aright[] = {0x00,0x08,0x0C,0x0E,0x0C,0x08,0x00,0x00}; // LCD character
|
||||
@ -43,17 +43,17 @@ LiquidCrystal_I2C lcd(0x27,16,2); // L
|
||||
|
||||
int v[2],b[2],r[2]={0};double q,rpm[2]={0},xpm[2]={0},xb[2]={0},xv[2]={0},rtime[2]; // speed and regulation
|
||||
long ac[2]={0},bc[2]={0}; // interrupt rpm counter
|
||||
long xts,sts,rts,swts,buts,savets,catts[2],stop[2],bts[2],vts[2]; // timing
|
||||
long xts,sts,rts,swts,buts,savets,catts[2],stop[2],bts[2],vts[2],ots[2]; // timing
|
||||
int bdelay,bprocess=0,enclast,encval,M=2,S=0; // button/encoder processing
|
||||
int F[2],bstate[2]={0},btime[2],cat[2],ctime[2],cstate[2]={0},bclr=0,SAVE=0,LOCK=0; // operating states
|
||||
char form[8],out[20]; // string buffer
|
||||
String cmd[8];int icmd[8];
|
||||
int ostate[2]={0},otime[2]={0}; // off timer
|
||||
char form[8],out[20];String cmd[8];int icmd[8]; // string buffer
|
||||
|
||||
|
||||
void setup() { ////////////////////////////////////////////////////////////////////////////////////////// SETUP
|
||||
Serial.begin(9600); // start serial
|
||||
|
||||
lcd.init();lcd.clear();lcd.backlight();lcd.createChar(0,aright);lcd.createChar(1,aup); // initialize lcd
|
||||
|
||||
pinMode(PWM0,OUTPUT);pinMode(PWM1,OUTPUT); // set PWM pins
|
||||
pinMode(CLK,INPUT);pinMode(DT,INPUT);pinMode(SW,INPUT); // set KY-040 pins
|
||||
digitalWrite(CLK,true);digitalWrite(DT,true);digitalWrite(SW,true); // turn ON pullup resistors
|
||||
@ -77,7 +77,7 @@ void setup() { /////////////////////////////////////////////////////////////////
|
||||
|
||||
enclast=digitalRead(CLK); // get encoder state
|
||||
|
||||
for (int i=0;i<2;i++) catts[i]=stop[i]=vts[i]=MS;xts=sts=rts=swts=buts=savets=MS; // timer
|
||||
for (int i=0;i<2;i++) catts[i]=stop[i]=vts[i]=ots[i]=MS;xts=sts=rts=swts=buts=savets=MS; // timer
|
||||
updatePWM();updatelcd();updatespeed();updatemarker(); // update all
|
||||
|
||||
slcd(0,0,5,VERSION); // show version
|
||||
@ -89,24 +89,30 @@ void loop() { //////////////////////////////////////////////////////////////////
|
||||
if (Serial.available() > 0) { ////////////////////////////////////////////////////////// serial communication
|
||||
int n=cutcmd(Serial.readString());
|
||||
int err=1;
|
||||
int i=cut(icmd[1],0,1);
|
||||
if (cmd[0]=="info" && n==1) {;err=0;}
|
||||
if (cmd[0]=="version" && n==1) {;SXN(VERSION);return;}
|
||||
if (cmd[0]=="speed" && n==3) {;v[icmd[1]]=cut(icmd[2],FANMIN,FANMAX);err=0;}
|
||||
if (cmd[0]=="bspeed" && n==3) {;b[icmd[1]]=cut(icmd[2],FANMIN,FANMAX);err=0;}
|
||||
if (cmd[0]=="btime" && n==3) {;btime[icmd[1]]=cut(icmd[2],0,60);err=0;}
|
||||
if (cmd[0]=="ctime" && n==3) {;ctime[icmd[1]]=cut(icmd[2],60,240);err=0;}
|
||||
if (cmd[0]=="rtime" && n==3) {;rtime[icmd[1]]=cut(icmd[2],0,240);err=0;}
|
||||
if (cmd[0]=="on" && n==2) {;fset(cut(icmd[1],0,1),1);err=0;}
|
||||
if (cmd[0]=="off" && n==2) {;fset(cut(icmd[1],0,1),0);err=0;}
|
||||
if (cmd[0]=="bon" && n==2) {;bset(cut(icmd[1],0,1),1);err=0;}
|
||||
if (cmd[0]=="boff" && n==2) {;bset(cut(icmd[1],0,1),0);err=0;}
|
||||
if (cmd[0]=="con" && n==2) {;cat[(int)cut(icmd[1],0,1)]=1;catts[(int)cut(icmd[1],0,1)]=MS;err=0;}
|
||||
if (cmd[0]=="coff" && n==2) {;cat[(int)cut(icmd[1],0,1)]=0;catts[(int)cut(icmd[1],0,1)]=MS;err=0;}
|
||||
if (cmd[0]=="save" && n==1) {;save();}
|
||||
if (cmd[0]=="speed" && n==3) {;v[i]=cut(icmd[2],FANMIN,FANMAX);err=0;}
|
||||
if (cmd[0]=="bspeed" && n==3) {;b[i]=cut(icmd[2],FANMIN,FANMAX);err=0;}
|
||||
if (cmd[0]=="btime" && n==3) {;btime[i]=cut(icmd[2],0,60);err=0;}
|
||||
if (cmd[0]=="ctime" && n==3) {;ctime[i]=cut(icmd[2],60,240);err=0;}
|
||||
if (cmd[0]=="rtime" && n==3) {;rtime[i]=cut(icmd[2],0,240);err=0;}
|
||||
if (cmd[0]=="on" && n==2) {;fset(i,1);err=0;}
|
||||
if (cmd[0]=="off" && n==2) {;fset(i,0);err=0;}
|
||||
if (cmd[0]=="bon" && n==2) {;bset(i,1);err=0;}
|
||||
if (cmd[0]=="boff" && n==2) {;bset(i,0);err=0;}
|
||||
if (cmd[0]=="con" && n==2) {;cat[i]=1;catts[i]=MS;err=0;}
|
||||
if (cmd[0]=="coff" && n==2) {;cat[i]=0;catts[i]=MS;err=0;}
|
||||
if (cmd[0]=="otime" && n==3) {;oset(i,icmd[2]);err=0;}
|
||||
|
||||
updatelcd();
|
||||
for (int i=0;i<2;i++) {
|
||||
SX(F[i]);SX(":");SX((int)(v[i]));SX(":");SX((int)(b[i]));SX(":");SX(rpm[i]);SX(":");
|
||||
SX(xpm[i]);SX(":");SX(r[i]);SX(":");SX(bstate[i]);SX(":");SX(btime[i]);SX(":");
|
||||
SX(cat[i]);SX(":");SX(ctime[i]);SX(":");SX(rtime[i]);SX(":");
|
||||
SX(cat[i]);SX(":");SX(ctime[i]);SX(":");SX(rtime[i]);SX(":");SX(otime[i]);SX(":");
|
||||
if (bstate[i]) SX((((long)btime[i]*60000)-(MS-(long)bts[i]))/1000+1); else SX(0);SX(":");
|
||||
if (ostate[i]) SX((((long)otime[i]*3600000)-(MS-(long)ots[i]))/1000+1); else SX(0);SX(":");
|
||||
}
|
||||
SX(VERSION);SX(":");SXN(err);
|
||||
}
|
||||
@ -116,6 +122,10 @@ void loop() { //////////////////////////////////////////////////////////////////
|
||||
|
||||
for (int i=0;i<2;i++) {
|
||||
|
||||
if (ostate[i] && MS-ots[i]>(long)otime[i]*3600000) { ////////////////////////////////////// check off timer
|
||||
otime[i]=0;ostate[i]=0;fset(i,0);
|
||||
}
|
||||
|
||||
if (cat[i] && MS-catts[i]>(long)ctime[i]*60000 && F[i]==1) { //////////////////////////// initiate cat fish
|
||||
catts[i]=MS;cstate[i]=1;F[i]=0;stop[i]=MS;updatePWM();updatespeed();
|
||||
}
|
||||
@ -199,6 +209,7 @@ void loop() { //////////////////////////////////////////////////////////////////
|
||||
if (S==3) cat[M]++; // cat 0 on/off
|
||||
if (S==4) ctime[M]+=10; // cat time 0 up
|
||||
if (S==5) rtime[M]+=10; // rise time 0 up
|
||||
if (S==6) otime[M]++; // off time 0 up
|
||||
}
|
||||
} else { // turn encoder counterclockwise
|
||||
if (M==2) S--; // scroll menu
|
||||
@ -209,20 +220,22 @@ void loop() { //////////////////////////////////////////////////////////////////
|
||||
if (S==3) cat[M]--; // cat 0 on/off
|
||||
if (S==4) ctime[M]-=10; // cat time 0 down
|
||||
if (S==5) rtime[M]-=10; // rise time 0 down
|
||||
if (S==6) otime[M]--; // off time 0 down
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<2;i++) if (b[i]<v[i]) b[i]=v[i];
|
||||
|
||||
if (M!=2) {
|
||||
if (S<=1) {;updatePWM();rts=MS+RDELAY;} // apply (boost) speed change fan 1
|
||||
if (S==2) btime[M]=cut(btime[M],0,60); // check boost time fan 0
|
||||
if (S==3) {;cat[M]=cut(cat[M],0,1);catts[0]=MS;} // check cat fan 0
|
||||
if (S==4) ctime[M]=cut(ctime[M],60,240); // check cat time fan 0
|
||||
if (S==5) rtime[M]=cut(rtime[M],0,240); // check rise time fan 0
|
||||
if (S<=1) {;updatePWM();rts=MS+RDELAY;} // apply (boost) speed change
|
||||
if (S==2) btime[M]=cut(btime[M],0,60); // check boost time
|
||||
if (S==3) {;cat[M]=cut(cat[M],0,1);catts[0]=MS;} // check cat
|
||||
if (S==4) ctime[M]=cut(ctime[M],60,240); // check cat time
|
||||
if (S==5) rtime[M]=cut(rtime[M],0,240); // check rise time
|
||||
if (S==6) oset(M,otime[M]); // check off time
|
||||
}
|
||||
|
||||
if (M==2) S=cut(S,0,5); // check menu mode
|
||||
if (M==2) S=cut(S,0,6); // check menu mode
|
||||
|
||||
SAVE++;updatelcd();delay(50);
|
||||
}
|
||||
@ -233,6 +246,10 @@ void loop() { //////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////// SUPPORT
|
||||
|
||||
void oset(int n,int t) { ///////////////////////////////////////////////////////////////// set switch off timer
|
||||
otime[n]=cut(t,0,99);ots[n]=MS;ostate[n]=otime[n]?1:0;
|
||||
}
|
||||
|
||||
void fset(int n,int s) { /////////////////////////////////////////////////////////////// set fan state (on/off)
|
||||
if (s==1) {
|
||||
rts=MS+RDELAY;F[n]=1;catts[n]=vts[n]=MS;r[n]=0;updatePWM();
|
||||
@ -243,9 +260,9 @@ void fset(int n,int s) { ///////////////////////////////////////////////////////
|
||||
|
||||
void bset(int n,int s) { ///////////////////////////////////////////////////////////// set boost state (on/off)
|
||||
if (s==1) {
|
||||
rts=MS+RDELAY;bstate[M]=1;bts[M]=MS;F[M]=1;vts[M]=MS;
|
||||
rts=MS+RDELAY;bstate[n]=1;bts[n]=MS;F[n]=1;vts[n]=MS;
|
||||
} else {
|
||||
bstate[M]=0;rts=MS+RDELAY;updatePWM();
|
||||
bstate[n]=0;rts=MS+RDELAY;updatePWM();
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,6 +277,7 @@ void updatelcd() { /////////////////////////////////////////////////////////////
|
||||
}
|
||||
if (S==4) {;slcd(1,1,5,"CTIME");ilcd(7+i*5,1,-4,int(ctime[i]));}
|
||||
if (S==5) {;slcd(1,1,5,"RTIME");ilcd(7+i*5,1,-4,int(rtime[i]));}
|
||||
if (S==6) {;slcd(1,1,5,"OTIME");ilcd(7+i*5,1,-4,int(otime[i]));}
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,7 +294,8 @@ void updatespeed() { ///////////////////////////////////////////////////////////
|
||||
else {
|
||||
if (F[i]) {
|
||||
if (bstate[i]) ilcd(1+i*3,0,-2, (((long)btime[i]*60000)-(MS-(long)bts[i]))/1000/60+1);
|
||||
else slcd(7+i*5,0,1," ");
|
||||
else if (ostate[i]) ilcd(1+i*3,0,-2, (((long)otime[i]*3600000)-(MS-(long)ots[i]))/1000/60/60+1);
|
||||
else slcd(0,0,1," ");
|
||||
ilcd(7+i*5,0,-4,round(xpm[i]));
|
||||
if ((!bstate[i] && xv[i]<v[i]) || (bstate[i] && xb[i]<b[i])) clcd(6+i*5,0,1);
|
||||
} else slcd(7+i*5,0,-4,"OFF");
|
||||
|
28
stirctl
28
stirctl
@ -19,18 +19,21 @@ $cmd=join(':',@ARGV);$cmd='info' if ($cmd=~/^\s*$/);
|
||||
@r=split(':',&scmd($cmd));
|
||||
|
||||
print " Left Right\n";
|
||||
printf("Stirrer On: %4d %4d\n", $r[0],$r[11]);
|
||||
printf("Speed: %4d %4d\n", $r[1],$r[12]);
|
||||
printf("Boost Speed: %4d %4d\n", $r[2],$r[13]);
|
||||
printf("RPM: %4d %4d\n", $r[3],$r[14]);
|
||||
printf("Average RPM: %4d %4d\n", $r[4],$r[15]);
|
||||
printf("Regulation: %4d %4d\n", $r[5],$r[16]);
|
||||
printf("Boost On: %4d %4d\n", $r[6],$r[17]);
|
||||
printf("Boost Time: %4d %4d\n", $r[7],$r[18]);
|
||||
printf("Catch On: %4d %4d\n", $r[8],$r[19]);
|
||||
printf("Catch Time: %4d %4d\n", $r[9],$r[20]);
|
||||
printf("Rise Time: %4d %4d\n", $r[10],$r[21]);
|
||||
printf("Error: %d\nVersion: %s\n", $r[23],$r[22]);
|
||||
printf("Stirrer On: %6d %6d\n", $r[0],$r[14]);
|
||||
printf("Speed: %6d %6d\n", $r[1],$r[15]);
|
||||
printf("Boost Speed: %6d %6d\n", $r[2],$r[16]);
|
||||
printf("RPM: %6d %6d\n", $r[3],$r[17]);
|
||||
printf("Average RPM: %6d %6d\n", $r[4],$r[18]);
|
||||
printf("Regulation: %6d %6d\n", $r[5],$r[19]);
|
||||
printf("Boost On: %6d %6d\n", $r[6],$r[20]);
|
||||
printf("Boost Time: %6d %6d\n", $r[7],$r[21]);
|
||||
printf("Catch On: %6d %6d\n", $r[8],$r[22]);
|
||||
printf("Catch Time: %6d %6d\n", $r[9],$r[23]);
|
||||
printf("Rise Time: %6d %6d\n", $r[10],$r[24]);
|
||||
printf("Off Time: %6d %6d\n", $r[11],$r[25]);
|
||||
printf("Boost Remain: %6d %6d\n", $r[12],$r[26]);
|
||||
printf("Off Remain: %6d %6d\n", $r[13],$r[27]);
|
||||
printf("Error: %d\nVersion: %s\n", $r[29],$r[28]);
|
||||
|
||||
|
||||
sub scmd() { ##################################################################################### send command
|
||||
@ -51,6 +54,7 @@ sub scmd() { ###################################################################
|
||||
}
|
||||
|
||||
$msg=~s/[\r\n]+//g;
|
||||
print "$msg\n";
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user