|
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <RotaryEncoder.h> |
|
|
|
#include "SevSeg.h" |
|
|
|
#include <SevSeg.h> |
|
|
|
#include <EveryTimer.h> |
|
|
|
#include <AccelStepper.h> |
|
|
|
|
|
|
@ -39,12 +39,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
#define ROT_BUTT 11 |
|
|
|
#define ROT_ENC_1 12 |
|
|
|
#define ROT_ENC_2 13 |
|
|
|
#define ROT_ENC_DIR -1 |
|
|
|
|
|
|
|
#define STEPPER_STEP 10 |
|
|
|
#define STEPPER_DIRECTION 0 |
|
|
|
#define STEPPER_ENABLE A5 |
|
|
|
|
|
|
|
|
|
|
|
//SETTINGS
|
|
|
|
#define SEVSEG_REFRESH 250 // Refresh rate in ms
|
|
|
|
#define SEVSEG_BRIGHTNESS 100 // 100%, full brightness
|
|
|
@ -80,6 +80,7 @@ bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros |
|
|
|
long refresh_timer = 0; |
|
|
|
|
|
|
|
long countdown = 0; |
|
|
|
byte days = 0; |
|
|
|
byte hours = 0; |
|
|
|
byte minutes = 0; |
|
|
|
byte seconds = 0; |
|
|
@ -94,7 +95,7 @@ void countdown_callback() { |
|
|
|
if (countdown < 0) { |
|
|
|
countdown = 0; |
|
|
|
} |
|
|
|
recalculate_HMS(); |
|
|
|
recalculate_DHMS(); |
|
|
|
//Serial.println(countdown);
|
|
|
|
} |
|
|
|
else { |
|
|
@ -116,8 +117,15 @@ void calculate_display_callback() { |
|
|
|
else { |
|
|
|
digitalWrite(SEVSEG_COLON, false); |
|
|
|
} |
|
|
|
//Display HH:MM or MM:SS if there is less than 1h left
|
|
|
|
if (hours) { |
|
|
|
//Display dd:HH if there is more than 1day left, HH:MM if less or MM:SS if there is less than 1h left
|
|
|
|
if (days) { |
|
|
|
char dispBuf[] = "0d00"; |
|
|
|
dispBuf[0] = days + 48; |
|
|
|
dispBuf[2] = (hours / 10) + 48; |
|
|
|
dispBuf[3] = (hours % 10) + 48; |
|
|
|
sevseg.setChars(dispBuf); |
|
|
|
} |
|
|
|
else if (hours) { |
|
|
|
sevseg.setNumber(100*hours+minutes); |
|
|
|
} else { |
|
|
|
sevseg.setNumber(100*minutes+seconds); |
|
|
@ -137,11 +145,12 @@ void update_encoder() { |
|
|
|
if (currVal != newVal) { |
|
|
|
currVal = newVal; |
|
|
|
if (mode == 0) { // Mode 0 : speed setting
|
|
|
|
multiplier = 10; |
|
|
|
if (current_rpm >= 500) { |
|
|
|
multiplier = 100; // default : 1 encoder step = +/- 10 step/min
|
|
|
|
// if speed > 500 : encoder step = +/- 100 step/min
|
|
|
|
} |
|
|
|
new_rpm += multiplier * dir; |
|
|
|
new_rpm += multiplier * dir * ROT_ENC_DIR; |
|
|
|
if (new_rpm < STEPPER_MIN_SPEED) { |
|
|
|
new_rpm = STEPPER_MIN_SPEED; |
|
|
|
} |
|
|
@ -151,20 +160,27 @@ void update_encoder() { |
|
|
|
} |
|
|
|
if (mode == 1) { //mode 1 : countdown setting
|
|
|
|
multiplier = 60; // default : 1 encoder step = +/- 1min
|
|
|
|
// if countdown > 1h : encoder step = +/- 1h
|
|
|
|
if (countdown >= 3600) { |
|
|
|
// if countdown > 1h : encoder step = +/- 10min (600s)
|
|
|
|
// if countdown > 1d : encoder step = +/- 1h (3600s)
|
|
|
|
if (countdown >= 86400) { |
|
|
|
multiplier = 3600; |
|
|
|
} |
|
|
|
else if (countdown >= 3600) { |
|
|
|
multiplier = 600; |
|
|
|
} |
|
|
|
countdown += multiplier * dir; |
|
|
|
countdown += multiplier * dir * ROT_ENC_DIR; |
|
|
|
|
|
|
|
//Min: 0 = no negative timer value
|
|
|
|
if (countdown < 0) { |
|
|
|
countdown = 0; |
|
|
|
} |
|
|
|
|
|
|
|
// Max: 86400s = 1 day
|
|
|
|
if (countdown >= 86400) { |
|
|
|
countdown = 86399; |
|
|
|
// Max: 864000s = 10 days
|
|
|
|
if (countdown >= 864000) { |
|
|
|
countdown = 863999; |
|
|
|
} |
|
|
|
recalculate_HMS(); |
|
|
|
|
|
|
|
recalculate_DHMS(); |
|
|
|
} |
|
|
|
Serial.print("RPM: "); |
|
|
|
Serial.print(new_rpm); |
|
|
@ -217,15 +233,23 @@ void update_stepper() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void recalculate_HMS() { |
|
|
|
minutes = (countdown / 60) % 60; |
|
|
|
if (countdown >= 3600) { |
|
|
|
hours = countdown / 3600; |
|
|
|
} |
|
|
|
else { |
|
|
|
hours = 0; |
|
|
|
seconds = countdown % 60; |
|
|
|
} |
|
|
|
void recalculate_DHMS() { |
|
|
|
//Calculate days, hours, minutes and seconds to be display
|
|
|
|
if (countdown >= 86400) { |
|
|
|
days = countdown / 86400; |
|
|
|
hours = (countdown % 86400) / 3600; |
|
|
|
} |
|
|
|
else { |
|
|
|
days = 0; |
|
|
|
minutes = (countdown / 60) % 60; |
|
|
|
if (countdown >= 3600) { |
|
|
|
hours = countdown / 3600; |
|
|
|
} |
|
|
|
else { |
|
|
|
hours = 0; |
|
|
|
seconds = countdown % 60; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void setup() |
|
|
|