Hi people,
I'm working on a arduino-based espresso-machine.
For this I use a DC-Motor (with a H-bridge) and a solenoid valve (controlled by a relay).
the motor should turn up, open the valve while turning up, close the valve and than turn down.
everything works fine, buuut I'd like that the valve turns on while the motor turns in one direction.
I know this doesn't work with delay and unfortunately I programmed with delay ...
I read that it's possible to change and to work like in the "blink without led"-example.
Unfortunately it's hard to understand and I really don't know how to continue ...
any help?
here is the actual code:
// pins
int dirPin = 4;
int pwmPin = 10;
int pushButton = 2;
int pressed = digitalRead(pushButton);
// motor up
int powerOnH = 240; // speed of the motor
int durationMovementH = 4000; // time of the rotation
int directionMovementH = HIGH; //direction
// motor down
int powerOnR= 240; // speed of the motor
int durationMovementR = 3785; // ime of the rotation
int directionMovementR = LOW; //direction
int powerOff = 0;
void setup(){
// pin modes
pinMode(dirPin,OUTPUT);
pinMode(pwmPin,OUTPUT);
pinMode(pushButton,INPUT);
digitalWrite(pushButton,HIGH);
pinMode(6,OUTPUT);
}
void loop(){
// push the button
int pressed = digitalRead(pushButton);
if (pressed == HIGH)
{
// up
digitalWrite(dirPin,directionMovementH);
// start
analogWrite(pwmPin,powerOnH);
// time
delay(durationMovementH);
// stop
analogWrite(pwmPin,powerOff);
//valve
digitalWrite(6,HIGH);
delay(2000);
digitalWrite(6,LOW);
//down
digitalWrite(dirPin,directionMovementR);
// start
analogWrite(pwmPin,powerOnR);
// time
delay(durationMovementR);
// stop
analogWrite(pwmPin,powerOff);
}
}
Moderator edit: CODE TAGS!