int brightness = 0;
int buttonState = 0;
void setup()
{
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT_PULLUP);
}
void loop()
{
buttonState = digitalRead(2);
if (buttonState == LOW) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
int sensorValue = analogRead(A1);
brightness = map(sensorValue, 0, 1023, 0, 255);
analogWrite(11, brightness);
delay(10);
}
I didn’t have my arduino yet, so i had to do this on tinkercad.
one led is triggered by a button, which acts as a digital sensor, and the other is controlled by a photoresistor, and increases in brightness the more light in the environment is detected. not really creative, but im crunched on time.
