Hola, por fin he conseguido mover mi motor BLDC con el potenciometro.
Por ahora lo tengo programado para ajustar la velocidad del motor con el potenciometro (0-100%) y crear una cuenta atrás con un par de botones, configurando los minutos y segundos de rodaje. Todo esto queda reflejado en un display. Una vez que tengo la configuración ajustada le doy a un ''Start'' button y el motor comienza a girar el tiempo establecido.
Ahora lo que quiero conseguir es crear 10 diferentes 'programas' con el potenciometro, es decir, si el arduino lee un porcentaje 0-10% del potenciometro, que sea el 'CASO 1', si lee entre el 10-20% 'CASO 2', y así sucesivamente....
Mi intención es asignar un número de revoluciones para cada CASO, para así poder tener un segumiento de las revoluciones a las que funciona el motor.
Mi duda es, ¿como puedo asignar esas revoluciones concretas para cada CASO? ¿podría configurar diferentes niveles de tensión en las salidas digitales para ajustar cada CASO?
Os dejo el código con lo que llevo hasta ahora:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
//VARIABLES FOR HALL SENSORS
int speed_vr=2; //VR motor speed 0-5V
int hall_sig=3; // Signal - Hall sensor (steps per round)
int direction_zf=4; // ZF motor direction (0V backwards - 5V fordwards)
int start=5; //EL Enable port control (5V runs - 0V stops)
//START BUTTON
int start_but=0; //Button for start(A1)
//VARIABLES FOR RUN TIME
unsigned long time1=0; //run time
int seconds=0; //show seconds on the LCD
int minutes=0; //show minutes on the LCD
int buts=0; //button for seconds(D8)
int butm=0; //button for minutes(D9)
//VARIABLES FOR SPEED CONTROL
int pot1=0; //pot for speed(A0)
int value=0; //value of pot in %
void setup() {
pinMode(speed_vr, OUTPUT);
pinMode(hall_sig, INPUT);
pinMode(direction_zf, OUTPUT);
pinMode(start, OUTPUT);
pinMode(start_but, INPUT);
pinMode(buts, INPUT);
pinMode(butm, INPUT);
pinMode(pot1, INPUT);
lcd.backlight();
lcd.init();
}
void loop(){
if(butm=digitalRead(9)==HIGH) //if the button has been pushed, we turn up the minutes
{
minutes=minutes+1;
if(minutes==6) minutes=0;
delay(50);
}
if(buts=digitalRead(8)==HIGH) //if the button has been pused, we turn up the seconds
{
seconds=seconds+1;
if(seconds==60) seconds=0;
delay(50);
}
while(analogRead(start_but)==0); //we can select the time1 until we push the button A1
time1= seconds+(minutes*60); //set the time in seconds
start_but=analogRead(1);
pot1=analogRead(0)/4; //read pot1 (A0). It's /4 because the analogRead has a rage of 0-255 (0-
1023)/4
analogWrite(speed_vr,pot1); //controlling the speed with the pot1
value =map(pot1,0,255,0,100); //convert pot1 lecture in %
if(start_but>0){
digitalWrite(start, HIGH);
while(time1>0)
{
delay(1000); //periods of 1 sec
time1--;
lcd.clear(); //clear the lcd
lcd.setCursor(0,0);
lcd.print("KALOTESTER");
lcd.setCursor(0,2);
lcd.print("Umdrehungen: ");
lcd.print(value);
lcd.print(" % ");
lcd.setCursor(0,3);
lcd.print("Laufzeit: ");
lcd.print(time1);
lcd.print(" s ");
delay(200);
}
if(time1==0)
{
digitalWrite(start, LOW); //when timer ends, motor stops
}
else{
digitalWrite(start, LOW);
}
}
lcd.clear(); //clear the lcd
lcd.setCursor(0,0);
lcd.print("KALOTESTER");
lcd.setCursor(0,2);
lcd.print("Umdrehungen: ");
lcd.print(value);
lcd.print(" % ");
lcd.setCursor(0,3);
lcd.print("Laufzeit: ");
lcd.print(time1);
lcd.print(" s ");
delay(200);
}