int Enable_output = 0;
int Vi_output = 0;
int Vn_output = 0;
int Up_output = 0;
int Dwn_output = 0;
long StartTime = 0;
long interval = 60000;
void setup() {
pinMode(48, OUTPUT); //TIC Enable switch pin 48 = output
pinMode(47, OUTPUT); //TIC Vi switch pin 47 = output
pinMode(43, OUTPUT); //TIC Vn switch pin 43 = output
pinMode(39, OUTPUT); //TIC Dwn switch pin 39 = output
pinMode(35, OUTPUT); //TIC Up switch pin 35 = output
digitalWrite(48, LOW); //Write Enable switch low on startup
digitalWrite(47, LOW); //Write Vi switch low on startup
digitalWrite(43, LOW); //Write Vn switch low on startup
digitalWrite(39, LOW); //Write Dwn switch low on startup
digitalWrite(35, LOW); //Write Up switch low on startup
}
void loop() {
unsigned long currentTime = millis();
unsigned long previousTime = currentTime - StartTime;
if (previousTime > interval) {
StartTime = currentTime;
}
if (previousTime < 5000) // 0 to 10 second point in the 50 second loop
{
Vi_output = LOW;
Vn_output = LOW;
Up_output = LOW;
Dwn_output = LOW;
Enable_output = LOW;
}
if (previousTime > 5000 && currentTime < 35000 ) // if inbetween 20 to 25 second point in the 50 second loop
{
Vi_output = HIGH;
Vn_output = LOW;
Up_output = HIGH;
Dwn_output = LOW;
Enable_output = HIGH;
}
if (previousTime > 35001 && currentTime < 55001 ) // if inbetween 25 to 35 second point in the 50 second loop
{
Vi_output = LOW;
Vn_output = HIGH;
Up_output = HIGH;
Dwn_output = LOW;
Enable_output = HIGH;
}
if (previousTime > 55001 && currentTime < 60000 ) // if inbetween 25 to 35 second point in the 50 second loop
{
Vi_output = LOW;
Vn_output = LOW;
Up_output = LOW;
Dwn_output = LOW;
Enable_output = LOW;
}
digitalWrite(48, Enable_output); //Enable
digitalWrite(47, Vi_output);// Vi
digitalWrite(43, Vn_output); //Vn
digitalWrite(35, Up_output); //Up
digitalWrite(39, Dwn_output); //Dwn
}
I am trying to produce a combined state of outputs within a 60second period.
0-5sec = all outputs low //standby time
5-35sec = vi, up and enable high //up at speed 1
35-55sec = vn, up and enable high //up at speed 2
55-60sec = all outputs low //standby time
If I manually write the pins without using any timing function the outputs switch fine, so wiring and connections is not an issue.
Please could anyone offer any help, I have looked at the millis tutorials but can't see the error?