// include the library code:
#include <Stepper.h>
#include <LiquidCrystal.h>
const int rs = 17, en = 16, d4 = 4, d5 = 0, d6 = 2, d7 = 15;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Motor PAP
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 5, 18, 19, 21);
// the previous reading from the analog input
int previous = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, ESP32!");
// Motor PAP
// Asignamos la velocidad en RPM (Revoluciones por Minuto)
stepper.setSpeed(5);
int val = analogRead(34);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0,1);
// print the number of seconds since reset:
// put your main code here, to run repeatedly:
// get the sensor value
int val = analogRead(34);
lcd.print(val);
int angulo = map(val,0,4095,-100,100);
lcd.setCursor(7, 1);
lcd.print("Ang: ");
lcd.setCursor(12,1);
lcd.print(angulo);
// Movemos el motor un número determinado de paso
stepper.step(angulo - previous);
// remember the previous value of the sensor
previous = angulo;
//stepper.step(angulo);
delay(100);
}