#define EB_FAST_TIME 120
#include <GyverOLED.h>
#include <EncButton.h>
#include "GyverOLEDMenu.h"
#define DEBUG //If you comment this line, the DPRINT & DPRINTLN lines are defined as blank.
#ifdef DEBUG //Macros are usually in all capital letters.
#define DPRINT(...) Serial.print(__VA_ARGS__) //DPRINT is a macro, debug print
#define DPRINTLN(...) Serial.println(__VA_ARGS__) //DPRINTLN is a macro, debug print with new line
#else
#define DPRINT(...) //now defines a blank line
#define DPRINTLN(...) //now defines a blank line
#endif
#include "BasicStepperDriver.h"
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 120
// Since microstepping is set externally, make sure this matches the selected mode
// If it doesn't, the motor will move at a different RPM than chosen
// 1=full step, 2=half step etc.
#define MICROSTEPS 1
// All the wires needed for full functionality
#define DIR 27
#define STEP 26
//Uncomment line to use enable/disable functionality
//#define SLEEP 13
// 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
//Uncomment line to use enable/disable functionality
//BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, SLEEP);
EncButton eb(18, 5, 19, INPUT_PULLUP);
GyverOLED<SSD1306_128x64> oled;
OledMenu<9, GyverOLED<SSD1306_128x64>> menu(&oled);
int d_p = 10;
int d_i = 1000;
int d_d = 50;
byte tt11 = 10;
float tt1 = 0.5;
boolean lgh = false;
int tt3 = 5;
int tt4 = 1000;
void setup() {
Serial.begin(115200); // Any baud rate should work
oled.init();
Wire.setClock(400000L);
oled.clear();
oled.update();
stepper.begin(RPM, MICROSTEPS);
menu.onChange(onItemChange, true);
menu.onPrintOverride(onItemPrintOverride); // если нужно сделать своё форматирование значений
menu.addItem(PSTR("<- Test")); // 0
menu.addItem(PSTR("GO!")); // 0
menu.addItem(PSTR("Eins P"), GM_N_INT(1), &d_p, GM_N_INT(0), GM_N_INT(100));
menu.addItem(PSTR("Zwei I"), GM_N_INT(1), &d_i, GM_N_INT(-5), GM_N_INT(20));
menu.addItem(PSTR("Dei D"), GM_N_INT(1), &d_d, GM_N_INT(0), GM_N_INT(7000)); // 3
menu.addItem(PSTR("V ОПР."), GM_N_FLOAT(0.01), &tt1, GM_N_FLOAT(1), GM_N_FLOAT(20));
menu.addItem(PSTR("TIMER 1"), GM_N_BYTE(1), &tt11, GM_N_BYTE(1), GM_N_BYTE(255)); // 5
menu.addItem(PSTR("asddА"), &lgh); // page 2
menu.addItem(PSTR("TIMER 3"), GM_N_INT(1), &tt3, GM_N_INT(1), GM_N_INT(5));
menu.addItem(PSTR("TIMER 4"), GM_N_INT(5), &tt4, GM_N_INT(0), GM_N_INT(1000)); // 8
menu.showMenu(true);
eb.attach(cb);
}
void onItemChange(const int index, const void* val, const byte valType) {
if (valType == VAL_ACTION) {
if (index == 0) {
menu.showMenu(false);
}
DPRINTLN(index);
}
}
boolean onItemPrintOverride(const int index, const void* val, const byte valType) {
// Допустим, что `TIMER 4`(index 8) - это минуты, которые мы можем менять. Отформатируем минуты по формату - `hh:mm`
if (index == 8) {
unsigned int hours = tt4 / 60; // [hh]
byte minutes = tt4 - (hours * 60); // [mm]
// отображаем нужном нам формате:
if (hours < 10) {
oled.print(0);
}
oled.print(hours);
oled.print(":");
if (minutes < 10) {
oled.print(0);
}
oled.print(minutes);
return true; // сигнализируем, что мы сами вызываем метод oled.print(...) с нужным нам форматированием
}
// возвращаем всегда `false`, если мы не собираемся для других пунктов меню принтить значение
return false;
}
void cb() {
switch (eb.action()) {
case EB_TURN:
if (eb.dir() == 1) {
menu.selectPrev(eb.fast());
} else {
menu.selectNext(eb.fast());
}
break;
case EB_CLICK:
menu.toggleChangeSelected();
break;
}
}
void loop() {
eb.tick();
// stepper.rotate(180);
/*
* Moving motor to original position using steps
*/
//stepper.move(-MOTOR_STEPS*MICROSTEPS);
}