Problem with code

[code]#include <Servo.h> // 

Servo myservo; // creating myservo object
int buttonPin = 36; // set button pin
int buttonState = 0; // set buttonState 
int buttonPin2 = 32; // set button pin
int buttonState2 = 0; // set buttonState
int led = 13;
int dirA = 12;
int dirB = 13; 
int speedA = 3;
int speedB = 11;

void setup()
{
myservo.attach(40); // attach the 2 pin to servo
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(led, OUTPUT);
}


void loop()
{
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
for (int i = 0 ; i <1 ;i++){
if (buttonState == LOW){
myservo.write(180); 
delay(1000);
myservo.write(0);
delay(1000);
delay(2000);
analogWrite (speedA, 1000);
analogWrite (speedB, 1000);
digitalWrite (dirA, HIGH);
digitalWrite (dirB, HIGH);
if (buttonState2 == LOW){
analogWrite (speedA, LOW);
delay(3000);// delay unwind
analogWrite (speedB, LOW);
if (buttonState2 == HIGH){
analogWrite (speedA, 1000);
analogWrite (speedB, 1000);
digitalWrite (dirA, HIGH);
digitalWrite (dirB, HIGH);
if (buttonState == HIGH){
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);       
}
}
}
}
}
}

I was trying to run this code but it stopped right before it says “if (buttonState2 == LOW){”. I couldn’t find what was wrong but i was wondering if anyone could tell me?

[/code]

for (int i = 0 ; i <1 ;i++){

Why bother with a loop?

The code is for a Halloween decoration and do you mean that I should take out that part?

analogWrite (speedA, 1000);

You may want to look at the documentation for analogWrite.

  1. What hardware have you got on your system.

  2. Layout (format) your code!

Mark

Hint Put your cursor on a { and the matching } will be hi lighted.

Then you will see why the code after if buttonstate2 == LOW is never ever run. It does not stop it just never passes that test.