Change logic button work
Hold enter button - enter change mode Repeat hold enter - exit change mode and save params Click enter button in change mode - drop changes and next cursor.
This commit is contained in:
parent
7572125fcb
commit
18662adfec
|
@ -3,6 +3,7 @@ LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars
|
|||
|
||||
// объявляем массив кнопок
|
||||
#define BTN_AMOUNT 5
|
||||
#define EB_HOLD 1000
|
||||
#include <EncButton2.h>
|
||||
EncButton2<EB_BTN> btn[BTN_AMOUNT];
|
||||
|
||||
|
@ -10,9 +11,12 @@ EncButton2<EB_BTN> btn[BTN_AMOUNT];
|
|||
|
||||
int cursor=0;
|
||||
int t_current=230;
|
||||
int t_current_temp=230;
|
||||
int t_set=230;
|
||||
int t_set_temp=230;
|
||||
int motor_speed=100;
|
||||
|
||||
int motor_speed_temp=100;
|
||||
int save=100;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
@ -50,12 +54,14 @@ void setup()
|
|||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void change_params(int cursor, int plus){
|
||||
if (cursor==0){
|
||||
void change_params(int save, int plus){
|
||||
//change current temperature
|
||||
if (save==0){
|
||||
if (plus==1){
|
||||
t_current++;
|
||||
}else{
|
||||
t_current--;
|
||||
t_current_temp++;
|
||||
}
|
||||
if (plus==0){
|
||||
t_current_temp--;
|
||||
}
|
||||
if (t_current>=300 || t_current<=0){
|
||||
//stop heating
|
||||
|
@ -63,77 +69,133 @@ void change_params(int cursor, int plus){
|
|||
lcd.setCursor(4,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(t_current);
|
||||
lcd.print(t_current_temp);
|
||||
}
|
||||
if (cursor==1){
|
||||
//change needed temperature
|
||||
if (save==1){
|
||||
if (plus==1){
|
||||
t_set++;
|
||||
}else{
|
||||
t_set--;
|
||||
t_set_temp++;
|
||||
}
|
||||
if (t_set>=300){
|
||||
t_set=300;
|
||||
if (plus==0){
|
||||
t_set_temp--;
|
||||
}
|
||||
if (t_set<=0){
|
||||
t_set=0;
|
||||
if (t_set_temp>=300){
|
||||
t_set_temp=300;
|
||||
}
|
||||
if (t_set_temp<=0){
|
||||
t_set_temp=0;
|
||||
}
|
||||
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(t_set);
|
||||
lcd.print(t_set_temp);
|
||||
}
|
||||
if (cursor==2){
|
||||
//change motor speed
|
||||
if (save==2){
|
||||
if (plus==1){
|
||||
motor_speed++;
|
||||
}else{
|
||||
motor_speed--;
|
||||
motor_speed_temp++;
|
||||
}
|
||||
if (motor_speed>=255){
|
||||
motor_speed=255;
|
||||
if (plus==0){
|
||||
motor_speed_temp--;
|
||||
}
|
||||
if (motor_speed<=-255){
|
||||
motor_speed=-255;
|
||||
if (motor_speed_temp>=255){
|
||||
motor_speed_temp=255;
|
||||
}
|
||||
if (motor_speed_temp<=-255){
|
||||
motor_speed_temp=-255;
|
||||
}
|
||||
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(motor_speed);
|
||||
lcd.print(motor_speed_temp);
|
||||
}
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
for (int i = 0; i < BTN_AMOUNT; i++) btn[i].tick();
|
||||
lcd.blink();
|
||||
for (int i = 0; i < BTN_AMOUNT; i++) btn[i].tick();
|
||||
//moving cursor
|
||||
if (cursor==0){
|
||||
lcd.setCursor(3, 0);
|
||||
}
|
||||
}
|
||||
if (cursor==1){
|
||||
//lcd.noBlink();
|
||||
lcd.setCursor(16, 0);
|
||||
}
|
||||
if (cursor==2){
|
||||
lcd.setCursor(10, 2);
|
||||
}
|
||||
if (btn[0].click()) {
|
||||
Serial.println("press enter, cursor=");
|
||||
//listen button held
|
||||
if (btn[0].held()) {
|
||||
Serial.println("hold enter");
|
||||
if (save==100){
|
||||
Serial.println("hold enter and save==100");
|
||||
save=cursor;
|
||||
lcd.noBlink();
|
||||
}else{
|
||||
|
||||
cursor++;
|
||||
if (cursor>2){
|
||||
cursor=0;
|
||||
if(save==0){
|
||||
Serial.println("hold enter and save==0");
|
||||
t_current=t_current_temp;
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(t_current);
|
||||
}
|
||||
Serial.println(cursor);
|
||||
if(save==1){
|
||||
Serial.println("hold enter and save==1");
|
||||
t_set=t_set_temp;
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(t_set);
|
||||
}
|
||||
if(save==2){
|
||||
Serial.println("hold enter and save==2");
|
||||
motor_speed=motor_speed_temp;
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(motor_speed);
|
||||
}
|
||||
lcd.blink();
|
||||
save=100;
|
||||
}
|
||||
}
|
||||
if (btn[1].click()) {
|
||||
Serial.println("press right, cursor=");
|
||||
Serial.println(cursor);
|
||||
change_params(cursor,1);
|
||||
//listen button click
|
||||
if (btn[0].click()) {
|
||||
Serial.println("press enter");
|
||||
if(save!=100){
|
||||
save=100;
|
||||
t_current_temp=t_current;
|
||||
t_set_temp=t_set;
|
||||
motor_speed_temp=motor_speed;
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(t_current);
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(17,0);
|
||||
lcd.print(t_set);
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(" ");
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(motor_speed);
|
||||
}
|
||||
cursor++;
|
||||
if (cursor>2){
|
||||
cursor=0;
|
||||
}
|
||||
}
|
||||
if (btn[2].click()) {
|
||||
Serial.println("press left, cursor=");
|
||||
Serial.println(cursor);
|
||||
change_params(cursor,0);
|
||||
if (btn[1].click() && save!=100) {
|
||||
Serial.println("press right and save!=100");
|
||||
change_params(save,1);
|
||||
}
|
||||
if (btn[2].click() && save!=100) {
|
||||
Serial.println("press left and save!=100");
|
||||
change_params(save,0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
17
README.md
17
README.md
|
@ -13,3 +13,20 @@ A simple firmware for a machine for processing plastic bottles into filament for
|
|||
|
||||
I started making a machine for pulling a ribbon from PET bottles into a rod for a 3D printer. I found a ready-made PetPull2 machine and it seemed wonderful to me. However, there was one downside. For some reason, the author of the machine uploads for him only the compiled firmware in hex format.
|
||||
I decided that maybe it would be a good practice for me to try to write my own firmware. And so that there are no more questions - I took instead of arduino nano - esp8266. The author of the machine does not have firmware for this controller, and the microcontroller itself is currently in short supply of semiconductors - cheaper than Arduino nano.
|
||||
|
||||
|
||||
// ================ BUTTON ================
|
||||
bool busy(); // вернёт true, если всё ещё нужно вызывать tick для опроса таймаутов
|
||||
bool state(); // текущее состояние кнопки (true нажата, false не нажата)
|
||||
bool press(); // кнопка была нажата [однократное срабатывание]
|
||||
bool release(); // кнопка была отпущена [однократное срабатывание]
|
||||
bool click(); // клик (нажата и отпущена) [однократное срабатывание]
|
||||
bool held(); // кнопка была удержана [однократное срабатывание]
|
||||
bool hold(); // кнопка удерживается [постоянное срабатывание]
|
||||
bool step(); // режим импульсного удержания
|
||||
bool step(uint8_t clicks); // режим импульсного удержания с предварительным накликиванием
|
||||
bool releaseStep(); // отпущена после режима step
|
||||
bool releaseStep(uint8_t clicks); // отпущена после режима step с предварительным накликиванием
|
||||
uint8_t clicks; // доступ к счётчику кликов
|
||||
uint8_t hasClicks(); // вернёт количество кликов, если они есть
|
||||
bool hasClicks(uint8_t num); // проверка на наличие указанного количества кликов
|
||||
|
|
Loading…
Reference in New Issue