#include "EncButton.h"
#include "LiquidCrystal_I2C.h"
#include "modes.h"
// 0x3F
class Program{
public:
Program(EncButton* enc, Button* btn, LiquidCrystal_I2C* lcd)
{
this->modes[0] = new AutomaticMode(enc, btn, lcd, "Automatic Mode");
this->modes[1] = new AutomaticMode(enc, btn, lcd, "Manual Mode");
this->display = lcd;
this->encoder = enc;
}
void do_step(){
}
void run()
{
while (true){
this->encoder->tick();
if (this->encoder->right()){
this->set_mode(1);
}
if (this->encoder->left()){
this->set_mode(-1);
}
if (this->encoder->click()){
this->modes[this->current_mode]->run();
}
}
}
void stop(){
this->display->clear();
this->display->setCursor(0, 0);
this->display->print("Fast Stopped");
}
private:
BaseMode* modes[2];
int len_modes = 2;
int current_mode = 0;
LiquidCrystal_I2C *display;
EncButton *encoder;
void set_mode(int count){
this->current_mode += count;
if (this->current_mode > (len_modes - 1)){
this->current_mode = 0;
}
else if (this->current_mode < 0){
this->current_mode = this->len_modes - 1;
}
this->display->clear();
this->display->setCursor(0, 0);
this->display->print("Mode:");
this->display->setCursor(0, 2);
this->display->print(this->modes[this->current_mode]->get_name());
}
};
EncButton *encoder_with_btn = new EncButton(34,35,32);
Button *stop_button = new Button(26);
LiquidCrystal_I2C *lcd = new LiquidCrystal_I2C(0x27, 20, 4);
Program program = Program(encoder_with_btn, stop_button, lcd);
void setup(){
Serial.begin(115200);
lcd->init(); // Инициируем работу с LCD дисплеем
lcd->backlight(); // Включаем подсветку LCD дисплея
lcd->setCursor(0, 0); // Устанавливаем курсор в позицию (0 столбец, 0 строка)
lcd->print("LCD"); // Выводим текст "LCD", начиная с установленной позиции курсора
lcd->setCursor(0, 3); // Устанавливаем курсор в позицию (0 столбец, 1 строка)
String a = "Hello world";
lcd->print(a);
}
void loop(){
program.run();
}