#include "EncButton.h"
#include "LiquidCrystal_I2C.h"
#include "modes.h"
#include "stepper.h"
// 0x3F
class Program{
public:
Program(EncButton* enc, Button* btn, LiquidCrystal_I2C* lcd, Stepper* stepper)
{
this->modes[0] = new AutomaticMode(enc, btn, lcd, "Automatic Mode");
this->modes[1] = new ManualMode(enc, btn, lcd, "Manual Mode", stepper);
this->display = lcd;
this->encoder = enc;
}
void run()
{
int a = 10;
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()){
Serial.println("Choosed");
this->modes[this->current_mode]->run();
}
}
}
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(33,25,26);
Button *stop_button = new Button(13);
LiquidCrystal_I2C *lcd = new LiquidCrystal_I2C(0x27, 20, 4);
Stepper *stepp = new Stepper(27, 18, 12, 200, false, false);
Program program = Program(encoder_with_btn, stop_button, lcd, stepp);
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();
}