Correct me if I'm misunderstanding you but does this describe the flow you want?
1. Check the signal level of pin 4
- If HIGH, go to 1.
- If LOW:
2. Blink LED for 1 second 6 times, then for 3 seconds once, then for 0.5 seconds twice.
3. Check the signal level of pin 4
- If HIGH, go to 1.
- If LOW:
4. Blink LED for 3 seconds twice.
5. Go to 3.
If so, what you have is mostly complete. What you are missing is step 3 and beyond in the pseudocode above.
void loop()
{ // Check the level of pin 4
if (digitalRead (brakeinput) == LOW)
{ // If LOW blink LED for 1 second 6 times
for (int i = 1; i<= 6; ++i)
{
digitalWrite (brakeoutput, HIGH);
delay (1000);
digitalWrite (brakeoutput, LOW);
delay (1000);
}
// then for 3 seconds once
for (int i = 1; i <= 1; ++i)
{
digitalWrite (brakeoutput, HIGH);
delay (3000);
digitalWrite(brakeoutput, LOW);
delay(500);
}
// then for 0.5 seconds twice
for (int i = 1; i <= 2; ++i)
{
digitalWrite (brakeoutput, HIGH);
delay (500);
digitalWrite (brakeoutput, LOW);
delay (500);
}
// Continuously check the level of pin 4
while (digitalRead(brakeinput) == LOW)
{ // If low blink LED for 3 seconds twice
for (int i = 1; i <= 2; ++i)
{
digitalWrite(brakeoutput, HIGH);
delay(3000);
digitalWrite(brakeoutput, LOW);
delay(500);
}
}
}
}
loop() is called repeatedly by the digispark firmware, so we don't need a while loop containing the whole thing since we're not storing any internal state. We do need a while loop at the end to keep checking the status of the input pin, since we only want to drop out of that sequence when the input goes high again.
The way I've written the for loops is personal preference. It makes it clear that you're using the loops as a counter and not an array index if you start at 1 and count up to and include your end value.