int E = 0;
int E2 = 0;
int E3 = 0;
int E4;
#include <Wire.h>
#include <LiquidCrystal_I2C_Hangul.h>
LiquidCrystal_I2C_Hangul lcd(0x27,16,2);
#include <Encoder.h>
Encoder encoder_1(3,2);
long stepn910 = 0;
long spedn910 = 0;
void setup() {
lcd.init();
lcd.backlight();
pinMode(4, INPUT_PULLUP);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
lcd.setCursor(0, 0);
lcd.print("Polosenue 0 mm");
lcd.setCursor(0, 1);
lcd.print("DBugati Ha 0 mm");
}
void loop() {
E = (encoder_1.read()/4);
E = (constrain(E,(-60),60));
if (E > E2) {
lcd.setCursor(11, 1);
lcd.print(" ");
lcd.setCursor(11, 1);
lcd.print(E);
}
if (E < E2) {
lcd.setCursor(11, 1);
lcd.print(" ");
lcd.setCursor(11, 1);
lcd.print(E);
}
E2 = (encoder_1.read()/4);
delay(7);
if (digitalRead(4) == 0) {
stepn910 = (E * 200);
spedn910 = 2000;
if (stepn910 < 0 && spedn910 > 0){
stepn910 = stepn910*-1;
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 0);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
stepn910 = stepn910*-1;
}
if (stepn910 > 0 && spedn910 > 0){
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 1);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
}
if (stepn910 == 0 | spedn910 == 0){
digitalWrite(9, 0);
digitalWrite(10, 0);
}
E3 = E + E3;
encoder_1.write(0);
}
delay(7);
if (E3 > E4) {
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.setCursor(11, 0);
lcd.print(E3);
}
if (E3 < E4) {
lcd.setCursor(11, 0);
lcd.print(" ");
lcd.setCursor(11, 0);
lcd.print(E3);
}
E4 = E + E3;
delay(7);
if (digitalRead(5) == 0) {
lcd.setCursor(11, 1);
lcd.print("Dom ");
do {
stepn910 = 1;
spedn910 = 2000;
if (stepn910 < 0 && spedn910 > 0){
stepn910 = stepn910*-1;
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 0);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
stepn910 = stepn910*-1;
}
if (stepn910 > 0 && spedn910 > 0){
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 1);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
}
if (stepn910 == 0 | spedn910 == 0){
digitalWrite(9, 0);
digitalWrite(10, 0);
}
} while (digitalRead(7) == 1);
E3 = 0;
lcd.setCursor(11, 1);
lcd.print("0 mm");
}
if (digitalRead(6) == 0) {
lcd.setCursor(11, 1);
lcd.print("Park ");
do {
stepn910 = (-1);
spedn910 = 2000;
if (stepn910 < 0 && spedn910 > 0){
stepn910 = stepn910*-1;
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 0);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
stepn910 = stepn910*-1;
}
if (stepn910 > 0 && spedn910 > 0){
for (int count = 0; count < stepn910; count++) {
digitalWrite(9, 1);
digitalWrite(10, 1);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
digitalWrite(10, 0);
delayMicroseconds(map(spedn910, 100, 1, 4000, 10000));
}
}
if (stepn910 == 0 | spedn910 == 0){
digitalWrite(9, 0);
digitalWrite(10, 0);
}
} while (digitalRead(8) == 1);
E3 = 0;
lcd.setCursor(11, 1);
lcd.print("0 mm");
}
}