int delayValue = 0;
int lightReading = 0;
int brightness = 0;
int buttonState = 0;
int LEDPin = 11;
int lightThreshold = 512;
void setup()
{
pinMode(2, INPUT);
pinMode(A0, INPUT);
pinMode(LEDPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
buttonState = digitalRead(2);
if (buttonState == HIGH) {
lightReading = analogRead(A0);
if (lightReading > lightThreshold) {
delayValue = 10;
} else {
delayValue = 5;
}
for (brightness = 0; brightness <= 255; brightness += 1) {
analogWrite(LEDPin, brightness);
delay(delayValue);
}
Serial.println("ON");
|