if and else statements

Hi, i'm new to arduino and i need a little help withe my code. basically i'm trying to make a fading LED turn into a blinking LED.

here my code:

const int ButtonPin = 2;
const int SleepPin =  9;
const int WakePin = 13;

void setup(){
  pinMode(ButtonPin, INPUT);
  pinMode(SleepPin, OUTPUT);
  pinMode(WakePin, OUTPUT);
}

void loop(){
  
  if(ButtonPin = HIGH);{
    digitalWrite(13, HIGH);  
    delay(1000);     
    digitalWrite(13, LOW);   
    delay(1000);            
  else;
    int brightness = 0;    
    int fadeAmount = 5;    
    
    analogWrite(9, brightness);    

    brightness = brightness + fadeAmount;

    if (brightness == 0 || brightness == 255) {
      fadeAmount = -fadeAmount ; 
    }       
    delay(30);                            
  }
}

thanks

You need to match your bracket for each part of the statement. if (stuff) { // if stuff } else { // else stuff } Also, your test statement needs a "==" instead of an "=" See the bits in bright green below

if(ButtonPin == HIGH);{ digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } else { int brightness = 0;

  if(ButtonPin == HIGH)[glow];[/glow]{

Also, ya gotta lose that furshlugginer semicolon, right?

Regards,

Dave

Try this:

const int ButtonPin = 2; const int SleepPin = 9; const int WakePin = 13;

// These need to be outside the main loop otherwise they will keep being reset each time through. int brightness = 0; int fadeAmount = 5;

void setup(){ pinMode(ButtonPin, INPUT); pinMode(SleepPin, OUTPUT); pinMode(WakePin, OUTPUT); }

void loop(){ if(digitalRead(ButtonPin) == HIGH) // You actualy need to read if the pin is high. { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } else { // Variables moved above.

analogWrite(SleepPin, brightness); // Since you declared 'SleepPin' as a const you may as well use it here.

brightness = brightness + fadeAmount; if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } delay(30); } }

thanks all for your help