Question

In: Electrical Engineering

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

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 and then released (make sure you debounce the press and release). Each time the button is pressed, the LED blinks a number of times corresponding to how many times the button has been pressed and released. For example, when the button is pressed and released for the first time, the LED will blink once; and when the button is pressed 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 was pressed).

Solutions

Expert Solution

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRD |= (1<<PD3); // Make third pin i.e PD3 as output to connect LED
DDRD &= ~(1<<PD0); // Make first pin i.e is PD0 as input to connect Butten Switch

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<<PD0) == 1) //If switch is pressed
    {
        count++;
        for(i=1;i<=count;i++)
        {
          PORTD |= (1<<PD3); //Turns ON LED
          _delay_ms(1000); //3 second delay
          PORTC &= ~(1<<PD3); //Turns OFF LED
        }
    }
}
}


Related Solutions

1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles...
1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles LED after 0.5 Seconds. Assume XTAL = 16MHz. To generate this delay use Timer 1 CTC (Clear Timer on Compare match) mode Programming. 2. Write a program to generate a square wave of frequency of 250 Hz with 50% duty cycle on PORTB.5. Assume XTAL = 16MHz. Use Timer 2 Normal Mode Programming. 3. Write a program using 16-bit timer to generate a square...
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays...
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays on when you push once and turns off and stays OFF when you push 3 times. This should repeat forever. 5. Write a code that S2(push button -P1.2) turns LED2 (Red LED- P9.7) ON and stays ON when you push once and turns OFF and stays OFF when you push 3 times. This should repeat five times. 6. Write a code that LED2 (Red...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...
1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
javaFX is there a way to change the text of a button and then that button...
javaFX is there a way to change the text of a button and then that button repeats to actions of the first button
Write a function that uses jQuery Ajax to load a link instead of a button. Similar...
Write a function that uses jQuery Ajax to load a link instead of a button. Similar to this example. https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_load But then it designates which chunk of text is shown based on which link is clicked based on id's. For example; Pseudocode: loaded file "txtfile.html" contains <body> id = red <p> *chunck of text* <p> id = blue <p> *chunk of text* <p> id = green <p> *chunk of text* <p> </body> Do this but with links with ids. So...
An R-C circuit with R = 100 ohm and C = 3 mF is connected to...
An R-C circuit with R = 100 ohm and C = 3 mF is connected to a 90 V source of emf. At t = 0 the switch is closed and the capacitor begins to charge. a) How much energy (in J) is stored in the capacitor at t = 0.7 s? b) What is the largest amount of energy that can be store in the capacitor?
ISYS 350, Assignment 2, Part 1: Create a C# Form with a textbox and a button....
ISYS 350, Assignment 2, Part 1: Create a C# Form with a textbox and a button. The box is for a user to enter a number of seconds. And when the user clicks the button, the program displays the equivalent number of hours, minutes and seconds using a MessageBox. Show method. If the seconds entered is less than 60, your program should only display the seconds; if the seconds is a least 60 and less than 3600, your program should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT