[Newbie] Basic blink program not working.

Hey,

I need to write a simple program, in which a LED has to blink at a variable speed. And I can control that speed with a button.
So far, I've just been trying to get the LED to blink at that variable speed, but it always seems to blink at the same speed.

Here's my code:

//Constants
const int ledPin = 0//Number of the LED pin

//Variables
boolean ledState = LOW;  //State the LED is in
int intervals[] = {200, 500, 1000, 2000, 10000}; //Intervals of time
int timeStep = 4; //Step of time in intervals

void setup() {
    //Set the LED pin as output
    pinMode(ledPin, OUTPUT);
}

void loop() {
  delay(intervals[timeStep]); //Waits for a certain amount of time based on timeStep
  
  if (ledState == LOW)  //Inverts the ledState
    ledState = HIGH;    //Cant I do ledState = !ledState ?
  else
    ledState = LOW;
  
  digitalWrite(ledPin, ledState);  //Sets the LED to the ledState
}

I should be able to change the speed with timeStep, but changing it does nothing for me.
My setup is just a cable going from pin 0 to a 220 ohm resistor, to a led, back to ground.

Can anybody tell me what I am doing wrong?

You're not changing the value of timestep

Hi Tjakka5

I should be able to change the speed with timeStep, but changing it does nothing for me.

How are you changing it? By changing this line in the program and uploading it again?

int timeStep = 4; //Step of time in intervals

it always seems to blink at the same speed.

Can you tell which interval it is blinking with?

const int ledPin = 0//Number of the LED pin

Pins 0 and 1 are used by the serial port. Better to use a different pin, e.g. 2.

Regards

Ray

hi
you need to change the timestep value by somthing like this:
timestep = 2;
and somewhere else in your code, change it again.
for example see this blink 10 times for each speed and then changes the speed

int led = 13;
int intervals[] = {200, 500, 1000, 2000, 5000}; //Intervals of time
int timestep = 0;
char i;
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  for(i=0;i<10;i++){
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(intervals[timestep]);
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    delay(intervals[timestep]);
  }
  timestep++;
  if (timestep==5)
    timestep=0;
}