Hi I am working on my first real Arduino project. It is a 3 fluid washing machine.I have almost every thing working. My problem is I need to be able to exit the cycle at any point in case of problems. An emergency stop if you will in the program.
I am using an Arduino Uno now and will move the program to a Mega when it gets here. Also I am simulating the agitator motors with a servo until i get my dc motor controller in.
Your thoughts please.
/* 3 8-ohm speaker on digital pin 7
/* Stir motors on pins 3 and 4 (servo stirrer used for now)
/* Drain valves on pins 8,9,10
/*Pumps on pins 11,12,13
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the motor position
int lpct = 4; /*variable to keep loop count */
//********************************
int pausetime = 1000; /* Standard delay */
int notepause = 150; /* delay between notes */
int stirtime = 2000; /* set for 20 min later */
int filltime = 2000; /* calibrate from pump */
int draintime =2000; /* measure drain time */
int pump1 = 11; /*setup pump 1 */
int pump2 = 12; /*setup pump 2 */
int pump3 = 13; /*setup pump 3 */
int valve1 = 8; /* setup valve 1 */
int valve2 = 9; /* setup valve 2 */
int valve3 = 10; /* setup valve 3 */
int stirrer1 = 3; /*setup stirrer 1 */
int stirrer2 = 4; /*setup stirrer 2 */
void setup() {
myservo.attach(2); // attaches the servo on pin 9 to the servo object
pinMode(pump1, OUTPUT); /* configure pin as output */
pinMode(pump2, OUTPUT); /* configure pin as output */
pinMode(pump3, OUTPUT); /* configure pin as output */
pinMode(valve1, OUTPUT); /*configure pin as output */
pinMode(valve2, OUTPUT); /*configure pin as output */
pinMode(valve3, OUTPUT); /*configure pin as output */
pinMode(stirrer1, OUTPUT); /* configure pin as output */
/* Initialization */
tone (7, 4978,100); /* Init tones */
delay (notepause);
tone (7, 4699,100);
delay (pausetime);
}
void loop() {
/* Start process */
/* CYCLE 1 */
/* play a single note on pin 7 for 100 ms: signifying cycle 1 */
tone(7, 4000, 100);
delay(notepause);
/* FILL */
digitalWrite(pump1, HIGH); /* turn on pump1 */
delay(filltime); /* fill tank */
digitalWrite(pump1, LOW); /* turn off pump1 */
/* STIR */
for (lpct = 0; lpct < 4; lpct +=1)
{
for(pos = 60; pos < 180; pos += 1) // goes from 0 speed to 180 speed
{ // in steps of 1
myservo.write(pos); // tell motor to go to speed in variable 'pos'
delay(15); // waits 15ms
}
for(pos = 180; pos>=60; pos-=1) // goes from 180 speed to 0 speedspeed
{
myservo.write(pos); // tell motor to go to position in variable 'pos'
delay(15); // waits 15ms for the motor to reach the position
}
}
/* Drain */
digitalWrite(valve1, HIGH); /* turn on valve1 */
delay(draintime); /* drain tank */
digitalWrite(valve1, LOW); /* turn off valve1 */
/* CYCLE 2 */
/* play a double note on pin 7 for 100 ms: signifying cycle 2 */
delay(pausetime);
tone(7, 4000, 100);
delay(notepause);
tone(7, 4000, 100);
delay(notepause);
digitalWrite(pump2, HIGH); /* turn on pump2 */
delay(filltime); /* fill tank */
digitalWrite(pump2, LOW); /* turn off pump2 */
/* STIR */
for (lpct = 0; lpct < 4; lpct +=1)
{
for(pos = 60; pos < 180; pos += 1) // goes from 0 speed to 180 speed
{ // in steps of 1
myservo.write(pos); // tell motor to go to position in variable 'pos'
delay(15); // waits 15ms for the motor to reach the position
}
for(pos = 180; pos>=60; pos-=1) // goes from 180 speed to 0 speed
{
myservo.write(pos); // tell motor to go to position in variable 'pos'
delay(15); // waits 15ms for the motor to reach the position
}
}
/* Drain */
digitalWrite(valve2, HIGH); /* turn on valve2 */
delay(draintime); /* drain tank */
digitalWrite(valve2, LOW); /* turn off valve2 */
/* CYCLE 3 */
/* play a triple note on pin 7 for 100 ms: signifying cycle 3 */
delay(pausetime);
tone(7, 4000, 100);
delay(notepause);
tone(7, 4000, 100);
delay(notepause);
tone(7, 4000, 100);
delay(notepause);
digitalWrite(pump3, HIGH); /* turn on pump3 */
delay(filltime); /* fill tank */
digitalWrite(pump3, LOW); /* turn off pump3 */
/* STIR */
for (lpct = 0; lpct < 4; lpct +=1)
{
for(pos = 60; pos < 180; pos += 1) // goes from 0 speed to 180 speed
{ // in steps of 1
myservo.write(pos); // tell motor to go to position in variable 'pos'
delay(15); // waits 15ms for the motor to reach the position
}
for(pos = 180; pos>=60; pos-=1) // goes from 180 speed to 0 speed
{
myservo.write(pos); // tell motor to go to position in variable 'pos'
delay(15); // waits 15ms for the motor to reach the position
}
}
/* Drain */
digitalWrite(valve3, HIGH); /* turn on valve3 */
delay(draintime); /* drain tank */
digitalWrite(valve3, LOW); /* turn off valve3 */
/* end of cycle */
/* play a 4 note sequence on pin 7 signifying end of cycle */
delay(pausetime);
tone(7, 3729, 100);
delay(notepause);
tone(7,2489 , 400);
delay(notepause);
tone(7, 4978, notepause);
delay(notepause);
tone(7, 4435, 400);
delay(notepause);
}
The biggest problem is the delay statements but i still need to be able to exit anywhere in the program.
Scratching my head???