#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
int step = 2;
int dir =3;
LiquidCrystal_I2C lcd1(0x27,16,2);
LiquidCrystal_I2C lcd2(0x26, 16, 2);
LiquidCrystal_I2C lcd3(0x25, 16, 2);
LiquidCrystal_I2C lcd4(0x24, 16, 2);
const int stepsPerRevolution = 200;
const float stepsPerDegree = stepsPerRevolution / 360.0;
int revolutions=0;
int steps=0;
int pot = A0;
int delay_time =0;
void setup() {
// put your setup code here, to run once:
pinMode(step, OUTPUT);
pinMode(dir, OUTPUT);
lcd1.init();
lcd1.backlight();
lcd2.init();
lcd2.backlight();
lcd3.init();
lcd3.backlight();
lcd4.init();
lcd4.backlight();
lcd1.print("LCD 1");
lcd1.setCursor(0,1);
lcd1.print("0 90");
lcd2.print("LCD 2");
lcd2.setCursor(0,1);
lcd2.print("91 180");
lcd3.print("LCD 3");
lcd3.setCursor(0,1);
lcd3.print("181 270");
lcd4.print("LCD 4");
lcd4.setCursor(0,1);
lcd4.print("271 360");
}
void loop() {
// put your main code here, to run repeatedly:
delay_time= map(analogRead(pot),0,1023,100,10);
digitalWrite(dir, HIGH);
digitalWrite(step, HIGH);
delay(delay_time);
digitalWrite(step, LOW);
delay(delay_time);
if(steps==200){
//++revolutions;
steps=0;
lcd1.setCursor(0,1);
lcd1.print("0 90");
lcd2.setCursor(0,1);
lcd2.print("91 180");
lcd3.setCursor(0,1);
lcd3.print("181 270");
lcd4.setCursor(0,1);
lcd4.print("271 360");
}
else{
steps++;
}
float angle= steps/stepsPerDegree;
if(angle>=0 && angle <=90){
for(int x=1;x<=14;x++){
int column = map(angle,0, 90,1,14);
lcd1.setCursor(column,1);
lcd1.print("_");
}
}
if(angle>=91 && angle <=180){
for(int x=2;x<=13;x++){
int column = map(angle,91, 180,2,13);
lcd2.setCursor(column,1);
lcd2.print("_");
}
}
if(angle>=181 && angle <=270){
for(int x=3;x<=12;x++){
int column = map(angle,181, 270,3,12);
lcd3.setCursor(column,1);
lcd3.print("_");
}
}
if(angle>=271 && angle <=360){
for(int x=3;x<=13;x++){
int column = map(angle,271, 360,3,13);
lcd4.setCursor(column,1);
lcd4.print("_");
}
}
//delay(10);
}
3
4
1
2