Changing modes with one touch button; on-mode1-mode2-mode3-off-on-mode1, etc.

Thank you Paul :slight_smile:

I have found this code that I've changed for the touch button and it works very well.

const int buttonPin = 7;
const int ledPin = 13; // the LED on the Lilypad
const int shoulder = 11; // Red LEDs
const int back = 10; // Red LEDs
const int frontdown = 9; // White LEDs
const int fronttop = 3; // White LEDs

int buttonState = 0;
int buttonPressed = 0;
int ledState = 0;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPin, OUTPUT); // sets the LedPin to be an output
pinMode(shoulder, OUTPUT); // sets the shoulder to be an output
pinMode(back, OUTPUT); // sets the back to be an output
pinMode(frontdown, OUTPUT); // sets the frontdown to be an output
pinMode(fronttop, OUTPUT); // sets the fronttop to be an output
pinMode(buttonPin, INPUT);
}

void loop()
{
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH && buttonPressed == 0)
{
ledState = 1 - ledState;
buttonPressed = 1;
}
if (buttonState == LOW && buttonPressed == 1)
{
buttonPressed = 0;
}

if (ledState == 1)
{
digitalWrite(ledPin, LOW);
digitalWrite(shoulder, HIGH); // sets the shoulder petal to LOW
digitalWrite(back, HIGH); // sets the back petal to LOW
digitalWrite(frontdown, HIGH); // sets the frontdown petal to LOW
digitalWrite(fronttop, HIGH); // sets the fronttop petal to LOW
}
else
{
digitalWrite(ledPin, LOW);
digitalWrite(shoulder, LOW); // sets the shoulder petal to LOW
digitalWrite(back, LOW); // sets the back petal to LOW
digitalWrite(frontdown, LOW); // sets the frontdown petal to LOW
digitalWrite(fronttop, LOW); // sets the fronttop petal to LOW
}
}

When I turn on the Lilypad, nothing happens before I touch the switch; then all the LEDs come on. When I touch the button again, I turn off all the LEDs.

How can I, in between there, when I touch the button the second time, instead of turning the LEDs off, I want to make the LEDs blink, and then with the third touch of the button I want to turn them off. How can this be achieved? I've been looking for examples that kind of look like what I am trying to do, but I find it difficult to transfer the code when I do not understand the function of that particular sentence/statement.

I will be very thankful for feedback with code examples with description of what the code means.