diff --git a/README.md b/README.md index 22dc75a..7e4eefe 100644 --- a/README.md +++ b/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>:`|set catch mode interval (60-240 min)| |`rtime:<0/1>:`|set speed rise time (0-240 sec)| +|`otime:<0/1>:`|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 diff --git a/stir.ino b/stir.ino index 78ca38c..7a540fd 100644 --- a/stir.ino +++ b/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]