Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I modify this code to toggle the LEDs? I just need to know where I need to add a delay so that when

How do I modify this code to toggle the LEDs? I just need to know where I need to add a delay so that when the button is pressed the LEDs will toggle until the button is pressed. Right now this code works so if you press the button the LEDs will turn on and once the button is pressed again. I'm just not sure where I need to add a delay so when the button is pressed the LEDs will toggle until the button is pressed again, which will then turn off the LEDs on the board.

Lab3_4.c

: Modify Lab3_3.c code such that the four lights will continuously toggle until the USER

button is pressed. The four lights will start toggling again once the USER button is pressed again. This behavior should repeat all the time.

Lab3_3.c code:

#define GREEN_LED 12

#define ORANGE_LED 13

#define RED_LED 14

#define BLUE_LED 15

#define PUSH_BUTTON 0

#include "stm32f4xx.h"

int main(void)

{

RCC -> AHB1ENR |= (1<<3 | 1<<0);

int i;

int j;

for (i= GREEN_LED; i <= BLUE_LED; i++)

{

GPIOD -> MODER |= (1<<(2*i));

GPIOD -> MODER &=~ (1<<(2*i+1));

GPIOD -> PUPDR &=~ (1<<(2*i) | 1<<(2*i+1));

GPIOD -> OTYPER &=~ (1<

}

GPIOA -> MODER &=~(1<<(2*PUSH_BUTTON)| 1<<(2*PUSH_BUTTON+1));

i =0;

while(i<1)

{

while (((GPIOA -> IDR)&(1<

{

}

if (((GPIOA -> IDR)&(1<

{

GPIOD -> ODR |= (1<

GPIOD -> ODR |= (1<

GPIOD -> ODR |= (1<

GPIOD -> ODR |= (1<

}

else

{

GPIOD -> ODR &=~ (1<

GPIOD -> ODR &=~ (1<

GPIOD -> ODR &=~ (1<

GPIOD -> ODR &=~ (1<

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions