I am working on building a photocopier that shoots paper everywhere for the musical 9 to 5 which is playing at my local High School tomorrow night Thursday May 16, 2013.
Basically it has one feeder motor, one "setup" motor, and an air valve.
I have everything working except for the "setup" motor.
The "setup" motor has to run for about 5s on start up.
The code I have written so far is pasted below.
char state_this = 'f';
boolean getBut1()
{
return digitalRead(7) == HIGH;
}
boolean getBut2()
{
return digitalRead(8) == HIGH;
}
void setMotorOff()
{
analogWrite(6,0);
}
void setMotorSlow()
{
analogWrite(6,200);
}
void setMotorFast()
{
analogWrite(6,255);
analogWrite(5,255);
}
void setMotor2On()
{
analogWrite(9,255);
}
void setMotor2Off()
{
analogWrite(9,0);
}
void setup()
{
Serial.begin(9600); // Set up serial communication at 9600bps
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(9,OUTPUT);
}
void loop()
{
char state_next;
boolean b1,b2;
state_next = state_this;
b1 = getBut1();
b2 = getBut2();
t1 = Time1();
t2 = Time2();
if (state_this == 'f') {
if ( t1) state_next = 's';
else if ( b2) state_next = 'f';
else if ( b1) state_next = 'a';
}
else if (state_this == 'a') {
if ( t1) state_next = 's';
else if ( b2) state_next = 'f';
else if (!b1) state_next = 'A';
}
else if (state_this == 'A') {
if ( t1) state_next = 's';
else if ( b2) state_next = 'f';
else if ( b1) state_next = 'b';
}
else if (state_this == 'b') {
if ( t1) state_next = 's';
else if ( b2) state_next = 'f';
else if (!b1) state_next = 'B';
}
else if (state_this == 'B') {
if ( t1) state_next = 's';
else if ( b2) state_next = 'f';
}
else if (state_this == 's') {
if ( t2) state_next = 'f';
else if (!t1) state_next = 'S';
}
else if (state_this == 'S') {
if ( t2) state_next = 'f';
}
else {
state_next = 'f';
}
if (state_this != state_next) {
// actions when entering a state
if (state_next == 'f') {
setMotorOff();
setMotor2Off();
}
else if (state_next == 'a') {
setMotorSlow();
}
else if (state_next == 'A') {
}
else if (state_next == 'b') {
setMotorFast();
}
else if (state_next == 'B') {
}
else if (state_next == 's') {
setMotor2On();
}
else if (state_next == 'S') {
}
}
state_this = state_next;
delay(10);
}
I need help figuring out how to trigger time1 at times less than 5000ms and time2 at times greater than 5000ms.
I tried doing this using millis for my time value, but found out that I could not compare it to a number.
Any help would be greatly appreciated as I only have tonight to finish it.