Simple Switching Sequences

I need help, in writing a code, which counts the button press (momentary) I do. The idea is that, if I press the button once, the LED on say pin 13 blinks continuously for 1000 miliseconds until I press it again,, in which case it blinks for 500 miliseconds, and so on. The idea is that I can control the output of a single pin by counting button presses,.

Please don't refer me to the counting button presses link on the playground (completely useless), but rater offer solutions, If someone could help me write the code, or even easier, just refer me to a good example of tutorial, (Except the one on the playground please).

Please help, Thanks

Sounds like a job for a Finite State Machine to me.
Each time through the loop() function read the button pin.
Every time the button is pressed add one to a variable.
Use the value of the variable with switch/case.
Write the code that should be executed in each case, but don't use delay() as it stops anything happening but the delay, including reading the button. Instead, use millis() for timing as in the BlinkWithoutDelay example in the IDE.

What UKHeliBob said, and make sure you debounce your button.

Please don't refer me to the counting button presses link on the playground (completely useless),

What you mean was that you didn't understand it, right? Get over it, instead of blaming the example.

Actually, I pasted the code into my IDE, and send it to my Arduino and followed the instructions, but the code didn't function.

Thanks for the help though :slight_smile:

Please post the code here so that we all know exactly what you tried.

Also I wrote a code, but the problem with it is, that once case 1 is fulfilled, it stopes 'searching' and reading the button, how to fix?

int led = 13;
int button = 8;

int val = 0;
boolean current = LOW;
boolean last = LOW;

void setup()
{
pinMode(led,OUTPUT);
pinMode(button,INPUT);
Serial.begin(9600);
}

boolean debounce(boolean last)
{
boolean current = digitalRead(button);

if(last != current)
{
delay(5);
current = digitalRead(button);
}
return current;
}

void loop(){
current = digitalRead(button);

if(last == LOW && current == HIGH)
{
val++;
Serial.println(val);
}

switch (val)
{
case 1:
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);

break;

case 2:
digitalWrite(led,HIGH);
delay(100);
digitalWrite(led,LOW);
delay(100);
break;
}

if(val > 2) val = 0;

}

Use code tags NOT quote tags for code that is the hash key.

You never call the debounce function so the variable last never changes, that is your problem.