Mia’s Arduino Homework 2

int brightness = 0; // how bright the LED is
// how many points to fade the LED by
int flag= 1;
int fadeAmount = 0;
int buttonState = 0;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(7, OUTPUT);
pinMode(3,INPUT);
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 7:
analogWrite(7, brightness);
buttonState = digitalRead(3);
if(buttonState==LOW){

flag = -flag;
}

if(flag==1){

1fadeAmount = 3;

}else{

1fadeAmount = 40;

}
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(50);

Author: Mia Xu

products of design student in sva