Question: How do I modify this code so that when I press the user button once the blue LED turns on, then when I press the

How do I modify this code so that when I press the user button once the blue LED turns on, then when I press the button twice the orange LED turns on, and then when I press the button three times all four LEDs turn on?

#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<

}

}

}

This code right now after you press you the button all the LEDs light up but now im not sure how to modify this code so when you press it a different amount of times a different LED will light up.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!