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...
Java Write a JavaFX application that displays a button and a number. Every time the button...
Java Write a JavaFX application that displays a button and a number. Every time the button is pushed, change the number to a random value between 1 and 100. Thank you and can you show a picture of the result as well
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
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and...
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and Port B and LED’s with PORTD. Write a code to read input from PortB and C and perform following. Addition of both inputs, Subtraction, Multiplication, Division, And, Or, Nor,Xor. (b)- A switch is connected to PD0 and LED’s to Port B and Port C. Write a code to perform following: When switch is 0 send your roll number to Port B. When Switch is...
1. A 1.5- volt battery is connected across an LED bulb, but the bulb does not...
1. A 1.5- volt battery is connected across an LED bulb, but the bulb does not “light up.” What are two possible reasons why it’s not lighting? (Both the battery and LED are in working order,) 2. ) In what way are an LED and a solar cell alike? In what ways are they different Please explain everything in detail, I have a lot of difficulty with science. Thank you!
1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. 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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT