Wednesday, August 21, 2013

project 1 and 2

int led1 = 9;
int amount = 0;
int fade = 5;
int led2 = 7;
int button = 2;
int on = 1;

void setup(){
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(button, INPUT);

}

void loop(){
if(amount % 100 == 0){
  if(on == 1){
  analogWrite(led2, 200);
  } else {
    analogWrite(led2, 0);
   on = 0;
  }
}
analogWrite(led1, amount);
amount = amount + fade;
if (amount == 0 || amount == 255){
  fade = -fade;
}
delay(30);
}

I made the led2 fade in and out and led1 to turn on and off based on fade amount using the modulo function.

No comments:

Post a Comment