beginner: button for different LED patterns

hi

im doing a little 8 step sequencer and i have basic problems. i want to use ONE push button to change between different patterns e.g:

when unit turns on all LED = off

start loop

when push button pressed 8 led's one after another go on and off, repeat

when push button pressed again 1st LED blinks twice, then decond LED blinks twice.....

when push button pressed again leds blink 3times then next led .......

end loop

also there is a potentiometer to controll the speed

i dont need the whole code but if someone could give me a kick start how this can be solved, would be nice

thanks randy

int sensorPin = 0;
int sensorValue = 0;



int ledPin1 = 0; 
int ledPin2 = 1;
int ledPin3 = 2;
int ledPin4 = 3;
int ledPin5 = 4;
int ledPin6 = 5;
int ledPin7 = 6;
int ledPin8 = 7;


void setup() {

  pinMode(ledPin1, OUTPUT);  
  pinMode(ledPin2, OUTPUT);  
  pinMode(ledPin3, OUTPUT);  
  pinMode(ledPin4, OUTPUT);  
  pinMode(ledPin5, OUTPUT);  
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

}


void loop() {
// programm 1
  
  sensorValue = analogRead(sensorPin);    
     
  // turn the ledPin on
  digitalWrite(ledPin1, HIGH);  
 delay(sensorValue);   
  digitalWrite(ledPin1, LOW);  
 delay(10);  
  digitalWrite(ledPin2, HIGH);
delay(sensorValue);   
  digitalWrite(ledPin2, LOW);    
  delay(10);       
  
  digitalWrite(ledPin3, HIGH);  
    delay(sensorValue);   
  digitalWrite(ledPin3, LOW);  
    delay(10);      
  digitalWrite(ledPin4, HIGH);  
    delay(sensorValue);    
  digitalWrite(ledPin4, LOW);  
   delay(10);          
  
   digitalWrite(ledPin5, HIGH);  
 delay(sensorValue);   
  digitalWrite(ledPin5, LOW);  
 delay(10);   
  digitalWrite(ledPin6, HIGH);
delay(sensorValue);   
  digitalWrite(ledPin6, LOW);    
  delay(10);             
  
  digitalWrite(ledPin7, HIGH);  
    delay(sensorValue);   
  digitalWrite(ledPin7, LOW);  
     delay(10);  
  digitalWrite(ledPin8, HIGH);  
    delay(sensorValue);    
  digitalWrite(ledPin8, LOW);  
   delay(10);          
  
   }

i dont need the whole code but if someone could give me a kick start how this can be solved, would be nice

First, you need a switch. Connect the switch to a digital pin. You need a pullup or pulldown resistor. There are internal pullup resistors you can use, in place of an external resistor.

Use the pinMode function to set the pin that the switch is connected to to INPUT.

Use the digitalWrite function to activate the pullup resistor, if needed.

Use the digitalRead function to determine if the switch is pressed or released.

When it is pressed, but wasn't before, increment the counter.

Read up on debouncing.

OK, that should get you started. More stuff here, if you get stuck: http://www.arduino.cc/en/Tutorial/HomePage

hi paul

i already have the push button on pin digital pin 12 and the LED's on digital 1 - 8 i know about the pullup resistor and i already have implemented that on my breadboard as well

i need code sniplets i tried the statechangedetection example but it does not work for my programm?

thanks

i tried the statechangedetection example but it does not work for my programm?

Is that a statement or a question?

If it did not work, why didn’t it? What did it do? What did it not do? What code were you running?

i tried both the switch cases and the button state.
i trashed the codes already since both did not work.
the switch case lightened up all leds and did not switch off
the button state i removed the serial thing and i was able to turn on the led with every 4th button switch but AAAARGH…
im looking in google for examples and it seems lots of people have exact the same request bit nobody got help. i could not find a proper example i could use as base for my project. im really disapointed as i am looking for 2 days now (before i ask for help in a forum)

So, forget, for the moment, about trying to light the LEDs up in patterns.

Write a sketch that sets a digital pin to input. In loop, read the state of that pin (that you have the switch connected to). Every time the button is pressed, increment the counter, and Serial.print() the counter value.

Get this working, coming here if you need help. When this works, you can make the Arduino do things more complicated than printing a message to the serial monitor.