Sketch help - moderate

Hi,
I am writing a script that will act as some form of kitchen timer. I have no display so I am simply using 5 LED's. My thoughts are that one presses reset and holds a push button down and LED's will light up one per second. One lit LED represents 5 mins of timing. I would have though that this would work by now but apparently not. I am getting led 1 on and no change what so ever, until after 5 mins it flashes. Any help please??

/*
Button

Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 7.

The circuit:

  • LED attached from pin 13 to ground

  • pushbutton attached to pin 2 from +5V

  • 10K resistor attached to pin 2 from ground

  • Note: on most Arduinos there is already an LED on the board
    attached to pin 13.

created 2005
by DojoDave http://www.0j0.org
modified 17 Jun 2009
by Tom Igoe

*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int led2Pin = 12;
const int led3Pin = 11;
const int led4Pin = 1; // the number of the LED pin
const int led5Pin = 9;
const int led6Pin = 7;
const int led7Pin = 6; // the number of the LED pin
const int led8Pin = 5;
const int led9Pin = 4;
const int led10Pin = 3;
const int speakerOut = 10;

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int tastyTimeVariable = 0; // my time variable that has 1 added
int i;
int n;

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(led5Pin, OUTPUT);
pinMode(led6Pin, OUTPUT);
pinMode(led7Pin, OUTPUT);
pinMode(led8Pin, OUTPUT);
pinMode(led9Pin, OUTPUT);
pinMode(led10Pin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(speakerOut, OUTPUT);

delay(3000);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(ledPin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led2Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led3Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led4Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led5Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led6Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led7Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led8Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led9Pin, HIGH);
}
else {
}

delay(1000);

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// add to timer
tastyTimeVariable = tastyTimeVariable + 1;
digitalWrite(led10Pin, HIGH);
}
else {
}

delay(1000);

digitalWrite(led10Pin, LOW);
digitalWrite(led9Pin, LOW);
digitalWrite(led8Pin, LOW);
digitalWrite(led7Pin, LOW);
digitalWrite(led6Pin, LOW);
digitalWrite(led5Pin, LOW);
digitalWrite(led4Pin, LOW);
digitalWrite(led3Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(ledPin, LOW);

delay(1000);

if (tastyTimeVariable = 0) {
}

else if (tastyTimeVariable = 1) {
digitalWrite (ledPin, HIGH);
delay(300L * 1000L);
for (i=0; i < 20; i++) {
analogWrite(speakerOut,128);
delay(250);
digitalWrite(speakerOut, LOW);
delay(250);
}
}

else if (tastyTimeVariable = 2) {
digitalWrite (led2Pin, HIGH);
digitalWrite (ledPin, HIGH);
delay(300L * 1000L);
digitalWrite (led2Pin, LOW);
delay(300L * 1000L);
for (i=0; i < 20; i++) {
analogWrite(speakerOut,128);
delay(250);
digitalWrite(speakerOut, LOW);
delay(250);
}
//sound alarm
}

else if (tastyTimeVariable = 3) {
digitalWrite (led3Pin, HIGH);
digitalWrite (led2Pin, HIGH);
digitalWrite (ledPin, HIGH);
delay(300L * 1000L);
digitalWrite (led3Pin, LOW);
delay(300L * 1000L);
digitalWrite (led2Pin, LOW);
delay(300L * 1000L);
//sound alarm
}

else if (tastyTimeVariable = 4) {
digitalWrite (led4Pin, HIGH);
digitalWrite (led3Pin, HIGH);
digitalWrite (led2Pin, HIGH);
digitalWrite (ledPin, HIGH);
delay(300L * 1000L);
digitalWrite (led4Pin, LOW);
delay(300L * 1000L);
digitalWrite (led3Pin, LOW);
delay(300L * 1000L);
digitalWrite (led2Pin, LOW);
delay(300L * 1000L);
for (i=0; i < 20; i++) {
analogWrite(speakerOut,128);
delay(250);
digitalWrite(speakerOut, LOW);
delay(250);
}
//sound alarm
}

else if (tastyTimeVariable = 5) {
digitalWrite (led5Pin, HIGH);
digitalWrite (led4Pin, HIGH);
digitalWrite (led3Pin, HIGH);
digitalWrite (led2Pin, HIGH);
digitalWrite (ledPin, HIGH);
delay(300L * 1000L);
digitalWrite (led5Pin, LOW);
delay(300L * 1000L);
digitalWrite (led4Pin, LOW);
delay(300L * 1000L);
digitalWrite (led3Pin, LOW);
delay(300L * 1000L);
digitalWrite (led2Pin, LOW);
delay(300L * 1000L);
for (i=0; i < 20; i++) {
analogWrite(speakerOut,128);
delay(250);
digitalWrite(speakerOut, LOW);
delay(250);
}
//sound alarm
}
}

anonymouse197,

The code as posted does not compile. You're probably missing a closing '}' for 'loop', or worse.

should work now. Sorry, It compiled fine for me when I tried it - just posted it wrong : )

For starters, you should check all of your 'if' statements. If they say something like:if (a = b)then they probably should be changed to:if (a == b)

Regards,

-Mike

Thanks Mike,
I will certainly check that one out.
Ari

@Mike

So what should I do in this sort of situation?

 else if (tastyTimeVariable > 10)  {
  }

This?

 else if (tastyTimeVariable >> 10)  {
  }

No. The > is the greater than operator. The statement you have is correct.

The = operator is an assignment operator. The == operator is the equality (test) operator.

Thanks Paul.
I will see if I can get it back up and running.

just posted it wrong

Amen.
Please use the # icon when posting code.