2022-04-16 11:07:13 +03:00
|
|
|
|
#if !defined(ESP8266)
|
|
|
|
|
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting.
|
|
|
|
|
#endif
|
2022-04-03 10:59:45 +03:00
|
|
|
|
#include <Wire.h>
|
|
|
|
|
//// Not work with Gyver Lib - EncButton
|
|
|
|
|
//const int sda=D1, scl=D2;
|
|
|
|
|
// #include <SoftwareWire.h> //make sure to not use beyond version 1.5.0
|
|
|
|
|
// // Check for "new" SoftwareWire that breaks things
|
|
|
|
|
// #if defined(TwoWire_h)
|
|
|
|
|
// #error incompatible version of SoftwareWire library (use version 1.5.0)
|
|
|
|
|
// #endif
|
|
|
|
|
// SoftwareWire Wire(D1,D2); // Create Wire object using desired Arduino pins
|
|
|
|
|
//////
|
2022-03-30 20:03:36 +03:00
|
|
|
|
#include <hd44780.h>
|
|
|
|
|
#include <hd44780ioClass/hd44780_I2Cexp.h>
|
|
|
|
|
hd44780_I2Cexp lcd; // declare lcd object and let it auto-configure everything.
|
2022-03-19 21:09:26 +03:00
|
|
|
|
|
2022-04-16 07:31:34 +03:00
|
|
|
|
|
2022-04-03 17:55:09 +03:00
|
|
|
|
#define L_BTN D4 // left button
|
2022-04-03 10:59:45 +03:00
|
|
|
|
#define R_BTN D3 // right button
|
2022-04-03 17:55:09 +03:00
|
|
|
|
#define E_BTN D5 // enter button
|
2022-04-05 23:27:49 +03:00
|
|
|
|
|
|
|
|
|
#define T_PIN A0 // thermistor pin
|
|
|
|
|
|
|
|
|
|
#define STEPS 400 // thermistor pin
|
|
|
|
|
#define STEP_PIN D7 // thermistor pin
|
|
|
|
|
#define DIR_PIN D8 // thermistor pin
|
|
|
|
|
#define EN_PIN D6 // thermistor pin
|
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
#define MOS_PIN D0
|
2022-03-19 21:09:26 +03:00
|
|
|
|
// Make custom characters:
|
|
|
|
|
byte motor_char_1[] = {
|
|
|
|
|
B00111,
|
|
|
|
|
B01000,
|
|
|
|
|
B10110,
|
|
|
|
|
B10101,
|
|
|
|
|
B10100,
|
|
|
|
|
B10100,
|
|
|
|
|
B01000,
|
|
|
|
|
B00111
|
|
|
|
|
};
|
|
|
|
|
byte motor_char_2[] = {
|
|
|
|
|
B11100,
|
|
|
|
|
B00010,
|
|
|
|
|
B01101,
|
|
|
|
|
B10101,
|
|
|
|
|
B00101,
|
|
|
|
|
B00101,
|
|
|
|
|
B00010,
|
|
|
|
|
B11100
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
//enable NTC thermistor
|
|
|
|
|
#include <GyverNTC.h>
|
|
|
|
|
// термистор на пине А0
|
|
|
|
|
// сопротивление резистора 10к
|
|
|
|
|
// тепловой коэффициент 3950
|
2022-04-05 23:27:49 +03:00
|
|
|
|
GyverNTC therm(T_PIN, 100000, 3950, 25, 8890);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
//enable button lib and define buttons array
|
2022-03-11 22:44:25 +03:00
|
|
|
|
#define BTN_AMOUNT 5
|
2022-03-12 16:37:22 +03:00
|
|
|
|
#define EB_HOLD 1000
|
2022-03-11 22:44:25 +03:00
|
|
|
|
#include <EncButton2.h>
|
|
|
|
|
EncButton2<EB_BTN> btn[BTN_AMOUNT];
|
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
//enable stepper
|
2022-04-07 11:49:37 +03:00
|
|
|
|
//#define GS_NO_ACCEL
|
|
|
|
|
// отключить модуль движения с ускорением (уменьшить вес кода)
|
2022-04-05 23:27:49 +03:00
|
|
|
|
#include <GyverStepper2.h>
|
|
|
|
|
GStepper2<STEPPER2WIRE> stepper(STEPS, STEP_PIN, DIR_PIN, EN_PIN);
|
|
|
|
|
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// These define's must be placed at the beginning before #include "ESP8266TimerInterrupt.h"
|
|
|
|
|
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
|
|
|
|
|
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
|
|
|
|
|
#define TIMER_INTERRUPT_DEBUG 0
|
|
|
|
|
#define _TIMERINTERRUPT_LOGLEVEL_ 0
|
|
|
|
|
// Select a Timer Clock
|
|
|
|
|
#define USING_TIM_DIV1 false // for shortest and most accurate timer
|
|
|
|
|
#define USING_TIM_DIV16 false // for medium time and medium accurate timer
|
|
|
|
|
#define USING_TIM_DIV256 true // for longest timer but least accurate. Default
|
|
|
|
|
#include "ESP8266TimerInterrupt.h"
|
|
|
|
|
volatile uint32_t lastMillis = 0;
|
|
|
|
|
#define TIMER_INTERVAL_MS 1000
|
|
|
|
|
// Init ESP8266 timer 1
|
|
|
|
|
ESP8266Timer ITimer;
|
2022-04-16 11:07:13 +03:00
|
|
|
|
#define P 16.67
|
|
|
|
|
#define I 0.75
|
|
|
|
|
#define D 91.91
|
|
|
|
|
#define DT 10
|
|
|
|
|
//PID regulator
|
|
|
|
|
#include "GyverPID.h"
|
|
|
|
|
GyverPID regulator(P, I, D, DT); // коэф. П, коэф. И, коэф. Д, период дискретизации dt (мс)
|
|
|
|
|
//Autotune PID
|
|
|
|
|
#include "PIDtuner.h"
|
|
|
|
|
PIDtuner tuner;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
//define vars
|
2022-04-16 11:07:13 +03:00
|
|
|
|
int max_speed = STEPS;
|
2022-03-17 23:20:14 +03:00
|
|
|
|
int cursor=1; //позиция курсора
|
2022-04-16 11:07:13 +03:00
|
|
|
|
int t_current=25;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// int t_current_temp=230;
|
2022-04-16 11:07:13 +03:00
|
|
|
|
int t_set=25;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// int t_set_temp=230;
|
2022-03-11 22:44:25 +03:00
|
|
|
|
int motor_speed=100;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// int motor_speed_temp=100;
|
2022-03-19 21:09:26 +03:00
|
|
|
|
int motor_state = 0;//0 - off, 1 - on
|
|
|
|
|
String motor_state_text = "OFF";
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// int motor_state_temp = 0;
|
|
|
|
|
// String motor_state_temp_text = "OFF";
|
2022-03-19 21:09:26 +03:00
|
|
|
|
int motor_dir = 0;//0 - forward, 1 - backward (FWD, BWD)
|
|
|
|
|
String motor_dir_text = "FWD";
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// int motor_dir_temp = 0;
|
|
|
|
|
// String motor_dir_temp_text = "FWD";
|
2022-03-19 21:09:26 +03:00
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
int save=100; //режим работы меню. 100- режим выбора. 1,2,3 - выбранное значение
|
2022-04-16 11:07:13 +03:00
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
long previousMillis = 0; // храним время последнего переключения светодиода
|
2022-04-05 02:26:34 +03:00
|
|
|
|
long interval = 600; // интервал между включение/выключением светодиода (1 секунда)
|
2022-04-16 11:07:13 +03:00
|
|
|
|
int autotune=0;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//===========Stepping in timer interrupts==================================
|
|
|
|
|
void IRAM_ATTR TimerHandler()
|
|
|
|
|
{
|
|
|
|
|
if (motor_state==1)
|
|
|
|
|
{
|
|
|
|
|
stepper.tick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//=====================================================================
|
2022-04-05 23:27:49 +03:00
|
|
|
|
void setup(){
|
2022-04-03 10:59:45 +03:00
|
|
|
|
Serial.begin(115200);
|
2022-04-16 11:07:13 +03:00
|
|
|
|
|
|
|
|
|
// Start interrupts timer. Interval in microsecs
|
2022-04-16 07:31:34 +03:00
|
|
|
|
if (ITimer.attachInterruptInterval(100, TimerHandler))
|
|
|
|
|
{
|
|
|
|
|
lastMillis = millis();
|
|
|
|
|
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(lastMillis);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Serial.println(F("Can't set ITimer correctly. Select another freq. or interval"));
|
|
|
|
|
}
|
2022-04-16 11:07:13 +03:00
|
|
|
|
//initial screen
|
|
|
|
|
init_screen();
|
|
|
|
|
//init buttons
|
|
|
|
|
btn[0].setPins(INPUT_PULLUP, L_BTN);
|
|
|
|
|
btn[1].setPins(INPUT_PULLUP, R_BTN);
|
|
|
|
|
btn[2].setPins(INPUT_PULLUP, E_BTN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regulator.setDirection(NORMAL); // направление регулирования (NORMAL/REVERSE). ПО УМОЛЧАНИЮ СТОИТ NORMAL
|
|
|
|
|
regulator.setLimits(0, 255); // пределы (ставим для 8 битного ШИМ). ПО УМОЛЧАНИЮ СТОЯТ 0 И 255
|
|
|
|
|
regulator.setpoint = t_set; // сообщаем регулятору температуру, которую он должен поддерживать
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init_screen(){
|
|
|
|
|
|
2022-04-05 23:27:49 +03:00
|
|
|
|
int istatus;
|
2022-03-30 20:03:36 +03:00
|
|
|
|
istatus = lcd.begin(20,4);
|
|
|
|
|
if(istatus)
|
|
|
|
|
{
|
2022-04-03 10:59:45 +03:00
|
|
|
|
Serial.println("-----Err init screen\n");
|
2022-03-30 20:03:36 +03:00
|
|
|
|
lcd.fatalError(istatus); // blinks error code on built in LED
|
|
|
|
|
}
|
|
|
|
|
//lcd.init(); // initialize the lcd
|
2022-03-11 22:44:25 +03:00
|
|
|
|
// Print a message to the LCD.
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//lcd.backlight();
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.createChar(0, motor_char_1);
|
|
|
|
|
lcd.createChar(1, motor_char_2);
|
|
|
|
|
|
2022-03-11 22:44:25 +03:00
|
|
|
|
lcd.setCursor(5,0);
|
|
|
|
|
lcd.print("Welcome to");
|
|
|
|
|
lcd.setCursor(0,1);
|
|
|
|
|
lcd.print("PetFilament Machine");
|
|
|
|
|
lcd.setCursor(2,2);
|
|
|
|
|
lcd.print("Firmware ver 0.1");
|
|
|
|
|
lcd.setCursor(0,3);
|
|
|
|
|
lcd.print("Powered By Mirivlad");
|
2022-04-03 10:59:45 +03:00
|
|
|
|
Serial.println("+++++Welcome screen ok");
|
|
|
|
|
delay(1000);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
lcd.clear();
|
|
|
|
|
lcd.setCursor(0,0);
|
|
|
|
|
lcd.print("Tc: ");//4,0 - set Temperature current
|
|
|
|
|
lcd.setCursor(4,0);
|
|
|
|
|
lcd.print(t_current);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
|
|
|
|
|
lcd.setCursor(0,1);
|
|
|
|
|
lcd.print("Ts: ");//4,1 - set Temperature setting
|
|
|
|
|
lcd.setCursor(4,1);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
lcd.print(t_set);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
lcd.setCursor(0,2);
|
|
|
|
|
lcd.print(" PID TUNE");//0,2 - set Temperature setting
|
|
|
|
|
// lcd.setCursor(4,1);
|
|
|
|
|
// lcd.print(t_set);
|
|
|
|
|
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(9,0);
|
|
|
|
|
lcd.write(0);
|
|
|
|
|
lcd.write(1);
|
|
|
|
|
lcd.setCursor(11,0);
|
|
|
|
|
lcd.print("spd: 100");//16,0 - Motor speed
|
|
|
|
|
lcd.setCursor(16,0);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
lcd.print(motor_speed);
|
|
|
|
|
|
2022-03-19 21:09:26 +03:00
|
|
|
|
if(motor_state==0){
|
|
|
|
|
motor_state_text="OFF";
|
|
|
|
|
}else{
|
|
|
|
|
motor_state_text=" ON";
|
|
|
|
|
}
|
|
|
|
|
lcd.setCursor(9,1);
|
|
|
|
|
lcd.write(0);
|
|
|
|
|
lcd.write(1);
|
|
|
|
|
lcd.setCursor(11,1);
|
|
|
|
|
lcd.print("act: OFF");//16,1 - Motor speed
|
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(motor_state_text);
|
|
|
|
|
|
|
|
|
|
if(motor_dir==0){
|
|
|
|
|
motor_dir_text="FWD";
|
|
|
|
|
}else{
|
|
|
|
|
motor_dir_text=" BWD";
|
|
|
|
|
}
|
|
|
|
|
lcd.setCursor(9,2);
|
|
|
|
|
lcd.write(0);
|
|
|
|
|
lcd.write(1);
|
|
|
|
|
lcd.setCursor(11,2);
|
|
|
|
|
lcd.print("dir: FWD");//16,2 - Motor speed
|
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(motor_dir_text);
|
2022-04-16 11:07:13 +03:00
|
|
|
|
}
|
|
|
|
|
void change_params(int save, int plus, int step_val){
|
|
|
|
|
//change current temperature
|
|
|
|
|
//save - value change params.
|
|
|
|
|
// 0 - current temperature
|
|
|
|
|
// 1 - needed temperature
|
|
|
|
|
// 2 - motor speed
|
|
|
|
|
// 3 - motor start|stop
|
|
|
|
|
// 4 - motor direction
|
|
|
|
|
if (save==0){
|
|
|
|
|
|
|
|
|
|
if (t_current>=300 || t_current<=0){
|
|
|
|
|
//stop heating
|
|
|
|
|
}
|
|
|
|
|
lcd.noBlink();
|
|
|
|
|
lcd.noCursor();
|
|
|
|
|
lcd.setCursor(4,0);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(4,0);
|
|
|
|
|
lcd.print(t_current);
|
|
|
|
|
Serial.println(t_current);
|
|
|
|
|
}
|
|
|
|
|
//change needed temperature
|
|
|
|
|
if (save==1){
|
|
|
|
|
|
|
|
|
|
if (plus==1){
|
|
|
|
|
t_set+=step_val;
|
|
|
|
|
}
|
|
|
|
|
if (plus==0){
|
|
|
|
|
t_set-=step_val;
|
|
|
|
|
}
|
|
|
|
|
if (t_set>=300){
|
|
|
|
|
t_set=300;
|
|
|
|
|
}
|
|
|
|
|
if (t_set<=0){
|
|
|
|
|
t_set=0;
|
|
|
|
|
}
|
2022-03-19 21:09:26 +03:00
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
lcd.setCursor(4,1);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(4,1);
|
|
|
|
|
lcd.print(t_set);
|
|
|
|
|
Serial.println("+++++Set needing temp ok");
|
|
|
|
|
}
|
|
|
|
|
//change motor speed
|
|
|
|
|
if (save==2){
|
|
|
|
|
if (plus==1){
|
|
|
|
|
motor_speed+=step_val;
|
|
|
|
|
}
|
|
|
|
|
if (plus==0){
|
|
|
|
|
motor_speed-=step_val;
|
|
|
|
|
}
|
|
|
|
|
if (motor_speed>=10000){
|
|
|
|
|
motor_speed=10000;
|
|
|
|
|
}
|
|
|
|
|
if (motor_speed<=0){
|
|
|
|
|
motor_speed=0;
|
|
|
|
|
}
|
|
|
|
|
if (motor_state==1){
|
|
|
|
|
if (motor_dir==0){
|
|
|
|
|
stepper.setSpeed(motor_speed);
|
|
|
|
|
}else{
|
|
|
|
|
stepper.setSpeed(-motor_speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lcd.setCursor(16,0);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,0);
|
|
|
|
|
lcd.print(motor_speed);
|
|
|
|
|
Serial.println("+++++Set motor speed ok");
|
|
|
|
|
}
|
|
|
|
|
//change motor state
|
|
|
|
|
if (save==3){
|
2022-04-16 07:31:34 +03:00
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
if (motor_state>=1){
|
|
|
|
|
motor_state=0;
|
|
|
|
|
motor_state_text="OFF";
|
|
|
|
|
// motor_state=0;
|
|
|
|
|
// motor_state_text="OFF";
|
|
|
|
|
stepper.disable();
|
|
|
|
|
}else{
|
|
|
|
|
// motor_state_temp=1;
|
|
|
|
|
// motor_state_temp_text="ON";
|
|
|
|
|
motor_state=1;
|
|
|
|
|
motor_state_text="ON";
|
|
|
|
|
stepper.enable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(motor_state_text);
|
|
|
|
|
Serial.println("+++++Set motor state ok");
|
|
|
|
|
}
|
|
|
|
|
if (save==4){
|
2022-03-11 22:44:25 +03:00
|
|
|
|
|
2022-04-16 11:07:13 +03:00
|
|
|
|
if (motor_dir>=1){
|
|
|
|
|
// motor_dir_temp=0;
|
|
|
|
|
// motor_dir_temp_text="FWD";
|
|
|
|
|
motor_dir=0;
|
|
|
|
|
motor_dir_text="FWD";
|
|
|
|
|
}else{
|
|
|
|
|
// motor_dir_temp=1;
|
|
|
|
|
// motor_dir_temp_text="BWD";
|
|
|
|
|
motor_dir=1;
|
|
|
|
|
motor_dir_text="BWD";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(motor_dir_text);
|
|
|
|
|
Serial.println("+++++Set motor direction ok");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-11 22:44:25 +03:00
|
|
|
|
void loop()
|
2022-03-17 23:20:14 +03:00
|
|
|
|
{
|
2022-04-16 11:07:13 +03:00
|
|
|
|
if (autotune==1){
|
|
|
|
|
tuner.setParameters(NORMAL, t_set, 15, 5000, 0.08, 15000, 500);
|
|
|
|
|
tuner.setInput(therm.getTempAverage());
|
|
|
|
|
tuner.compute();
|
|
|
|
|
analogWrite(MOS_PIN, tuner.getOutput());
|
|
|
|
|
if (tuner.getAccuracy() > 95){
|
|
|
|
|
autotune=0;
|
|
|
|
|
// выводит в порт текстовые отладочные данные, включая коэффициенты
|
|
|
|
|
tuner.debugText();
|
|
|
|
|
lcd.setCursor(0,3);
|
|
|
|
|
lcd.print(" ");//0,2 - set Temperature setting
|
|
|
|
|
lcd.setCursor(0,3);
|
|
|
|
|
lcd.print(tuner.getPID_p());//0,2 - set Temperature setting
|
|
|
|
|
lcd.setCursor(6,3);
|
|
|
|
|
lcd.print(tuner.getPID_i());//0,2 - set Temperature setting
|
|
|
|
|
lcd.setCursor(12,3);
|
|
|
|
|
lcd.print(tuner.getPID_d());//0,2 - set Temperature setting
|
|
|
|
|
|
|
|
|
|
regulator.Kp = tuner.getPID_p();
|
|
|
|
|
regulator.Ki = tuner.getPID_i();
|
|
|
|
|
regulator.Kd = tuner.getPID_d();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//t_current=therm.getTemp();
|
|
|
|
|
t_current=therm.getTempAverage();
|
2022-03-17 23:20:14 +03:00
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
|
|
|
|
|
|
//проверяем не прошел ли нужный интервал, если прошел то
|
|
|
|
|
if(currentMillis - previousMillis > interval) {
|
|
|
|
|
// сохраняем время последнего переключения
|
|
|
|
|
previousMillis = currentMillis;
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(0,100,0);
|
2022-04-16 11:07:13 +03:00
|
|
|
|
}
|
|
|
|
|
if (autotune!=1){
|
|
|
|
|
regulator.setpoint = t_set;
|
|
|
|
|
regulator.input = t_current; // сообщаем регулятору текущую температуру
|
|
|
|
|
// getResultTimer возвращает значение для управляющего устройства
|
|
|
|
|
// (после вызова можно получать это значение как regulator.output)
|
|
|
|
|
// обновление происходит по встроенному таймеру на millis()
|
|
|
|
|
regulator.getResult();
|
2024-01-27 06:02:15 +03:00
|
|
|
|
analogWrite(D0, regulator.getResultTimer()); // отправляем на мосфет
|
2022-04-16 11:07:13 +03:00
|
|
|
|
}
|
2022-04-07 11:49:37 +03:00
|
|
|
|
if (motor_state == 1){
|
|
|
|
|
if (motor_dir == 0){
|
|
|
|
|
stepper.setSpeed(motor_speed);
|
2022-04-05 23:27:49 +03:00
|
|
|
|
}else{
|
2022-04-07 11:49:37 +03:00
|
|
|
|
stepper.setSpeed(-motor_speed);
|
2022-04-05 23:27:49 +03:00
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
stepper.disable();
|
|
|
|
|
}
|
2022-03-19 22:00:49 +03:00
|
|
|
|
|
2022-04-07 11:49:37 +03:00
|
|
|
|
|
|
|
|
|
|
2022-03-17 23:20:14 +03:00
|
|
|
|
if (save==100){
|
|
|
|
|
lcd.noBlink();
|
|
|
|
|
lcd.cursor();
|
|
|
|
|
}
|
2022-03-11 22:44:25 +03:00
|
|
|
|
for (int i = 0; i < BTN_AMOUNT; i++) btn[i].tick();
|
2022-04-07 11:49:37 +03:00
|
|
|
|
|
2022-03-11 22:44:25 +03:00
|
|
|
|
if (cursor==1){
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(3, 1);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
|
|
|
|
if (cursor==2){
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(15, 0);
|
|
|
|
|
}
|
|
|
|
|
if (cursor==3){
|
|
|
|
|
lcd.setCursor(15, 1);
|
|
|
|
|
}
|
|
|
|
|
if (cursor==4){
|
|
|
|
|
lcd.setCursor(15, 2);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
2022-04-16 11:07:13 +03:00
|
|
|
|
|
|
|
|
|
if (cursor==5){
|
|
|
|
|
lcd.setCursor(0, 2);
|
|
|
|
|
}
|
2022-03-12 16:37:22 +03:00
|
|
|
|
//listen button held
|
|
|
|
|
if (btn[0].held()) {
|
|
|
|
|
Serial.println("hold enter");
|
2022-03-17 23:20:14 +03:00
|
|
|
|
//enter change mode
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if (save==100){
|
|
|
|
|
Serial.println("hold enter and save==100");
|
|
|
|
|
save=cursor;
|
2022-03-17 23:20:14 +03:00
|
|
|
|
lcd.blink();
|
|
|
|
|
lcd.cursor();
|
2022-03-12 16:37:22 +03:00
|
|
|
|
}else{
|
2022-03-17 23:20:14 +03:00
|
|
|
|
//enter save mode
|
2022-04-05 23:27:49 +03:00
|
|
|
|
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if(save==1){
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("hold enter and save==1");
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//t_set=t_set_temp;
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(4,1);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(" ");
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(4,1);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(t_set);
|
2022-03-17 23:20:14 +03:00
|
|
|
|
lcd.cursor();
|
|
|
|
|
lcd.blink();
|
|
|
|
|
delay(3000);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if(save==2){
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("hold enter and save==2");
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//motor_speed=motor_speed_temp;
|
2022-04-07 11:49:37 +03:00
|
|
|
|
if (motor_state==1){
|
|
|
|
|
if (motor_dir==0){
|
|
|
|
|
stepper.setSpeed(motor_speed);
|
|
|
|
|
}else{
|
|
|
|
|
stepper.setSpeed(-motor_speed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,0);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(" ");
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,0);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(motor_speed);
|
2022-03-17 23:20:14 +03:00
|
|
|
|
lcd.cursor();
|
|
|
|
|
lcd.blink();
|
|
|
|
|
delay(3000);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
}
|
2022-03-19 21:09:26 +03:00
|
|
|
|
if(save==3){
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("hold enter and save==3");
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//motor_state=motor_state_temp;
|
|
|
|
|
//motor_state_text=motor_state_temp_text;
|
2022-04-05 23:27:49 +03:00
|
|
|
|
if (motor_state==0){
|
2022-04-07 11:49:37 +03:00
|
|
|
|
stepper.stop();
|
2022-04-05 23:27:49 +03:00
|
|
|
|
stepper.disable();
|
|
|
|
|
}else{
|
|
|
|
|
stepper.enable();
|
|
|
|
|
}
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(motor_state_text);
|
|
|
|
|
lcd.cursor();
|
|
|
|
|
lcd.blink();
|
|
|
|
|
delay(3000);
|
|
|
|
|
}
|
|
|
|
|
if(save==4){
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("hold enter and save==4");
|
2022-04-16 07:31:34 +03:00
|
|
|
|
//motor_dir=motor_dir_temp;
|
|
|
|
|
//motor_dir_text=motor_dir_temp_text;
|
2022-04-05 23:27:49 +03:00
|
|
|
|
//тормозим перед сменой направления
|
|
|
|
|
stepper.brake();
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,2);
|
2022-04-07 11:49:37 +03:00
|
|
|
|
lcd.print(motor_dir_text);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.cursor();
|
|
|
|
|
lcd.blink();
|
|
|
|
|
delay(3000);
|
|
|
|
|
}
|
2022-04-16 11:07:13 +03:00
|
|
|
|
|
|
|
|
|
if (save==5){
|
|
|
|
|
autotune=1;
|
|
|
|
|
lcd.setCursor(0,2);
|
|
|
|
|
lcd.cursor();
|
|
|
|
|
lcd.blink();
|
|
|
|
|
delay(3000);
|
|
|
|
|
}
|
2022-03-17 23:20:14 +03:00
|
|
|
|
lcd.noBlink();
|
|
|
|
|
lcd.cursor();
|
|
|
|
|
//lcd.blink();
|
2022-03-12 16:37:22 +03:00
|
|
|
|
save=100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//listen button click
|
|
|
|
|
if (btn[0].click()) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press enter");
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if(save!=100){
|
|
|
|
|
save=100;
|
2022-04-16 07:31:34 +03:00
|
|
|
|
// t_current_temp=t_current;
|
|
|
|
|
// t_set_temp=t_set;
|
|
|
|
|
// motor_speed_temp=motor_speed;
|
|
|
|
|
// motor_state_temp=motor_state;
|
|
|
|
|
// motor_state_temp_text=motor_state_text;
|
|
|
|
|
// motor_dir_temp=motor_dir;
|
|
|
|
|
// motor_dir_temp_text=motor_dir_text;
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.setCursor(4,0);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(4,0);
|
|
|
|
|
lcd.print(t_current);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(4,1);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(" ");
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(4,1);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(t_set);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,0);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(" ");
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,0);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
lcd.print(motor_speed);
|
2022-03-19 21:09:26 +03:00
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,1);
|
|
|
|
|
lcd.print(motor_state_text);
|
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(" ");
|
|
|
|
|
lcd.setCursor(16,2);
|
|
|
|
|
lcd.print(motor_dir_text);
|
2022-03-12 16:37:22 +03:00
|
|
|
|
}
|
|
|
|
|
cursor++;
|
2022-04-16 11:07:13 +03:00
|
|
|
|
if (cursor>5){
|
2022-03-17 23:20:14 +03:00
|
|
|
|
cursor=1;
|
2022-03-12 16:37:22 +03:00
|
|
|
|
}
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
2022-03-19 22:00:49 +03:00
|
|
|
|
//TODO: how to know how much click done before held?
|
|
|
|
|
//int clicks1 = btn[1].hasClicks();
|
|
|
|
|
//int clicks2 = btn[2].hasClicks();
|
|
|
|
|
if (btn[1].step(2) && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press right and save!=100 and HOLD");
|
|
|
|
|
//Serial.println(clicks1);
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,1,3);
|
|
|
|
|
}
|
|
|
|
|
if (btn[2].step(2) && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press right and save!=100 and HOLD");
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,0,3);
|
|
|
|
|
}
|
|
|
|
|
if (btn[1].step(4) && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press right and save!=100 and HOLD");
|
|
|
|
|
//Serial.println(clicks1);
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,1,4);
|
|
|
|
|
}
|
|
|
|
|
if (btn[2].step(4) && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press right and save!=100 and HOLD");
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,0,4);
|
|
|
|
|
}
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if (btn[1].click() && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press right and save!=100");
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,1,1);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
2022-03-12 16:37:22 +03:00
|
|
|
|
if (btn[2].click() && save!=100) {
|
2022-03-30 20:03:36 +03:00
|
|
|
|
//Serial.println("press left and save!=100");
|
2022-03-19 22:00:49 +03:00
|
|
|
|
change_params(save,0,1);
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|
2022-03-12 16:37:22 +03:00
|
|
|
|
|
2022-03-11 22:44:25 +03:00
|
|
|
|
}
|