An LED is connected to PD3 and a Button is connected to PD0. Write a C...

Free

80.2K

Verified Solution

Question

Electrical Engineering

An LED is connected to PD3 and a Button is connected to PD0.Write a C program that will wait for the button to be pressed andthen released (make sure you debounce the press and release). Eachtime the button is pressed, the LED blinks a number of timescorresponding to how many times the button has been pressed andreleased. For example, when the button is pressed and released forthe first time, the LED will blink once; and when the button ispressed and released the second time, the LED will blink twice,etc. The button will be pressed once and release once each time.The LED shows a count (accumulated number of times Button waspressed).

Answer & Explanation Solved by verified expert
4.0 Ratings (406 Votes)

#include
#include

int main(void)
{
DDRD |= (1< DDRD &= ~(1<

unsigned int count = 0;      // initilize a count variable for make led glow number of time propotional to switch
unsigned int i;
while(1) // Runs infinite loop
{
    if(PIND & (1<     {
        count++;
        for(i=1;i<=count;i++)
        {
          PORTD |= (1<           _delay_ms(1000); //3 second delay
          PORTC &= ~(1<         }
    }
}
}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students