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<
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
