Hi there
this is going to seem like a silly question I know. but I am trying to sequence a variety of outputs to occur one after the other with varying delay times.
I am trying my best to avoid delay at all costs so I am utilizing a technique outlined in the "doing many things at the same time" example.
however I am running into an issue in regards to my timing statements not running in sequential order. the first if statement engages fine but the sequence then seems to skip right to the base state. most examples I have found tend to have only the two states, if and else. I want to run through a sequence of states before reaching my base state which is my else.
#include <PLDuino.h>
using namespace PLDuino;
//Includes required to use Roboclaw library
#include <SoftwareSerial.h>
#include "RoboClaw.h"
RoboClaw roboclaw(&Serial3,10000);
int buttonstate1 = 0;
#define address1 0x80
bool sequence = false;
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
void setup() {
PLDuino::init();
}
void loop()
{
roboclaw.begin(9600);
currentMillis = millis();
buttonstate1 = digitalRead(30);
if (buttonstate1 == LOW)
{
roboclaw.ForwardBackwardM1(address1,127); //start Motor1 forward at full speed
roboclaw.ForwardBackwardM2(address1,127);
digitalWrite(PLDuino::RELAY1, HIGH); //close relay 1
previousMillis = currentMillis;
if(currentMillis - previousMillis > 7000)
{
roboclaw.ForwardBackwardM1(address1,0); //motor one slows
roboclaw.ForwardBackwardM2(address1,0);
digitalWrite(PLDuino::RELAY1, LOW); //open relay 1, planning to move the relay operation to a seperate function
previousMillis = currentMillis;
}
if(currentMillis - previousMillis >= 500)
{
roboclaw.ForwardBackwardM1(address1,100); //motor continues at 70 percent speed
roboclaw.ForwardBackwardM2(address1,100);
}
if(currentMillis - previousMillis >= 20000)
{
roboclaw.ForwardBackwardM1(address1,0);
roboclaw.ForwardBackwardM2(address1,0); //motor slows down to near stop
previousMillis = currentMillis;
}
if(currentMillis - previousMillis >= 4250)
{
roboclaw.ForwardBackwardM1(address1,64); //motor brakes
roboclaw.ForwardBackwardM2(address1,64);
previousMillis = currentMillis;
}
}
else
{
roboclaw.ForwardBackwardM1(address1,64);
roboclaw.ForwardBackwardM2(address1,64);
}
}
its a simple problem I am well aware, I am getting mightily irritated by the whole thing and would be very grateful for the input.