hi,
I am looking for some advice on this program I am having a problem with.
The simulation is for a food blender. Ie one start switch to switch the system on and off. The switch should allow any of the three different speed selector switches, slow, medium and fast to operate only if the on/off switch is on and not to work if the on/off switch is off.
The on/off switch is input 2. The three speeds are inputs 3,4 and 5
The answer seems obvious, but for some reason it's puzzling me.
Many thanks
Derek
/*
course assignment - household appliance
*/
int MOTOR = 9; // the pin for the MOTOR
void setup()
{
pinMode(MOTOR,OUTPUT); // tell Arduino MOTOR is an output
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}
void loop()
{
if (digitalRead (3)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 50); // Sets the PWM mark:space ratio speed LOW.
while(!digitalRead(3)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}
else if (digitalRead (4)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 127); // Sets the PWM mark:space ratio speed MEDIUM.
while(!digitalRead(4)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}
else if (digitalRead (5)== HIGH) // if switch is pressed then jump to next line and switch on motor
{
analogWrite(MOTOR, 255); // Sets the PWM mark:space ratio speed HIGH.
while(!digitalRead(5)== HIGH)
{
delay(10); // do nothing, just delay a very tiny amount
}
}
else
{
digitalWrite(MOTOR, LOW);
}
}