Nice diagram. Good job - on both of them. ![]()
I only call out attention to the one you replaced with an edit to show that explaining the sequence you want can be tricky. Also I had done some work on the previous drawing, no large deal.
Anyway, considerably improved specifiaction from my point of view. The diagram makes what you trying to do very clear and suggests a number of variously clever approaches.
Here is a tiny demo program of one way to do this. It is certainly not too clever, but it would generalize better in other use cases than something that fully exploited the exact thing you are doing, which believe me could be very tersely expressed at the cost of simplicity and flexibility.
Maybe one of the heavies will show off something like that and amaze. Us.
The stepping function in the below code uses a switch/case arrangement to decide what to do as the numbered steps go by. Put you finger on the code and follow it along; you can play with it here also
const byte redLED = 6;
const byte whiteLED = 7;
void setup() {
Serial.begin(115200);
Serial.println("timed step world!");
pinMode(redLED, OUTPUT);
pinMode(whiteLED, OUTPUT);
}
void loop() {
timedStep();
}
# define STEP 777 // base unit of time ms
void timedStep()
{
static unsigned long lastAttention;
static unsigned int ignoreFor = 0;
static unsigned stepNumber;
unsigned long now = millis();
// see if it is time to do anything
if (now - lastAttention < ignoreFor)
return; // no. just return
// the below runs only after the "ignoreFor" time has elapsed again
// note time we are doing anythin
lastAttention = now;
Serial.print("stepping ");
Serial.println(stepNumber);
switch (stepNumber) {
case 4 :
digitalWrite(redLED, HIGH);
break;
case 5 :
digitalWrite(redLED, LOW);
break;
case 6 :
digitalWrite(whiteLED, HIGH);
break;
case 7 :
digitalWrite(whiteLED, LOW);
break;
}
// move on to next or reset step
stepNumber++;
if (stepNumber >= 10) stepNumber = 0;
// how long until we need to pay attention?
// this ould be fixed, or set on a case-by-case basis in te switch statemebt
ignoreFor = STEP;
}
a7