Question

A button is connected to p1.0 and an LED is connected to P2.0. Write code with PWM so that if the...

A button is connected to p1.0 and an LED is connected to P2.0. Write code with PWM so that if the button is pressed the LED is on 70%, but if the button is not pressed the LED is on 10%

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Semantic Network non-pressed BUTTON Iconnected to PIN Code int button-1 buttonStateLOW C should cause LED connected to ] PIN

pressed BUTTON .. [connected to ] PIN Code int button-1 buttonState HIGH Cshould cause CLED connected to PIN 2 ode Code int l

int button = 1;
int led = 2;

int buttonState = 0;
int npressedBrightness = 25;
int pressedBrightness = 178;

void setup () {
pinMode(led,OUTPUT);
pinMode(button, INPUT) ;
}

void loop() {
  
   buttonState = digitalRead(button);
  
   if (buttonState == HIGH) {
       analogWrite(led, pressedBrightness);
   }
  
   else {
       analogWrite(led, npressedBrightness);
   }
    delay(30);
}

Add a comment
Know the answer?
Add Answer to:
A button is connected to p1.0 and an LED is connected to P2.0. Write code with PWM so that if the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT