LED BRIGHTNESS ADJUST WITH PUSH BUTTON

LED brighness push

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/LED_BRIGHTNESS.zip

int pinIncrease = 2;
int pinDecrease = 3;
int pinLED = 11;
int brightness = 0;

void setup() {
Serial.begin(9600);
pinMode(pinIncrease, INPUT);
pinMode(pinDecrease, INPUT);
pinMode(pinLED, OUTPUT);
digitalWrite(pinIncrease, HIGH);
digitalWrite(pinDecrease, HIGH);
}

void loop() {
brightness = constrain(brightness, 0, 255);
analogWrite(pinLED, brightness);
Serial.println(brightness);
delay(100);

if(digitalRead(pinIncrease) == LOW){
brightness++;
}else if(digitalRead(pinDecrease) == LOW){
brightness–;
}
}

3 thoughts on “LED BRIGHTNESS ADJUST WITH PUSH BUTTON

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s