Hello,
Im currently working on a Protein mashine.
i have 2 Potentiometer Inputs (1 for Waterpumpmotor duration and 1 for mixingmotor duration) and 1 start button
I want the 2 Motors to run independently from eachother (Depending on the Potentiometer input)
But with the delay funktion, either both or none run at the same time. I know it somehow works with milis, but i cant get it to run. (Later on i want to use a Steppermotor for the Proteinpowder)
Thanks in advance!
here my code so far.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Stepper.h>
//----------------Stepper-----------//
const int stepsPerRevolution = 2048;
// Wiring:
// Pin 3 to IN1 on the ULN2003 driver
// Pin 6 to IN2 on the ULN2003 driver
// Pin 8 to IN3 on the ULN2003 driver
// Pin 12 to IN4 on the ULN2003 driver
// Create stepper object called 'myStepper', note the pin order:
Stepper myStepper = Stepper(stepsPerRevolution, 3, 8, 6, 12);
//------------------//
LiquidCrystal_I2C lcd(0x27,16,2);
int motor1_A=11; //WasserPumpe
int motor1_B=10; //
int motor2_A = 4; // Rührer
int motor2_B = 5; //
int buttonStart = 22; //Pushbutton1
int buttonRuehrmotor = 23; //Pushbutton2
int potPinWasser = 7; //Potentiometer
int potPinProtein = 8; //Potentiometer
double val = 0; // variable
// the setup routine runs once when you press reset:
void setup() {
//--------Stepper----------//
// Set the speed to 5 rpm:
myStepper.setSpeed(16);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(motor1_A,OUTPUT);
pinMode(motor1_B,OUTPUT);
// make the pushbutton's pin an input:
pinMode(buttonStart, INPUT);
pinMode(buttonRuehrmotor,INPUT);
pinMode(potPinWasser, INPUT);
pinMode(potPinProtein, INPUT);
lcd.begin();
lcd.backlight();
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
double value = analogRead(7); //Wasserpumpe
int value2 = analogRead(8); //Protein
int buttonStatebuttonStart = digitalRead(buttonStart);
int buttonStatebuttonRuehrmotor = digitalRead(buttonRuehrmotor);
/---------LCD-----------/
//lcd.begin();
//lcd.backlight();
lcd.setCursor(0,0);
lcd.print(value/1705); //Max 0,6 Liter
lcd.print(" Liter");
lcd.setCursor(0,1);
lcd.print(value2/20); //Max 0,6 Liter
lcd.print(" g Protein");
//delay(10000);
//lcd.noBacklight();
//lcd.clear();
/-----------------------------/
if(buttonStatebuttonStart == HIGH){
digitalWrite(motor1_A, HIGH);
digitalWrite(motor1_B,LOW);
digitalWrite(motor2_A, HIGH);
digitalWrite(motor2_B,LOW);
myStepper.step(-stepsPerRevolution);
delay(value*4);
}
if(buttonStatebuttonRuehrmotor == HIGH){
digitalWrite(motor1_A, LOW);
digitalWrite(motor1_B,LOW);
digitalWrite(motor2_A, HIGH);
digitalWrite(motor2_B,LOW);
}
else {
digitalWrite(motor1_A, LOW);
digitalWrite(motor1_B,LOW);
digitalWrite(motor2_A, LOW);
digitalWrite(motor2_B,LOW);
}
Serial.println(buttonStatebuttonStart);
//Serial.println(buttonRuehrmotor);
//Serial.println(value2);
delay(1); // delay in between reads for stability
}