int led = 9;
int brightness = 0;
int fadeAmount = 5;
int buttonPin = 2;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH){
Serial.println("HIGH");
}
else
{
Serial.println("LOW.");
}
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255){
fadeAmount = -fadeAmount;
}
delay(10);
}