cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make the onboard LED blink with a button press?

RMcn.1
Associate II

I am using the Nucleo-F767ZI board.

I have the normally open of the switch wired to 5V.

Common is to pin A0 and to R10K then pulled down to GND.

When the button is pressed the pin A0 will go from 0V to ~5V.

Want to blink LED1 at say 1Hz, then when button pressed blink frequency is changed to say 0.5Hz.

Would also accept switching from illuminating LED1 to illuminating LED2 with a button press.

Background history: I've found programming very difficult, only began to get my feet wet with Arduino hobby projects. Some sort of programming dyslexia. Now with the jump to this F7 board, IDE, and apparent change in code layout (main loop?)/ seemingly less user friendly names (HAL_toggle_makecomplex).. I'm getting bogged down. Before you ask - the boss saw my Arduino sticker then made me the microcontroller SME... Said "do what you can do and do it quickly". Whelp, can't do much but can ask for step by step help. Unfortunately, I can't bring you all doughnuts and coffee for your help but here's some O's: 00oO0oO0o0o

7 REPLIES 7
RMcn.1
Associate II

Great, thank you. I will work through each of these.

Piranha
Chief II

And, if you want to learn real development, not only CubeMX clicking and generating non-working bloatware, then start with this:

https://www.embeddedrelated.com/showarticle/453.php

RMcn.1
Associate II

Piranha, thank you. I had just gotten to the MOOC and found this note on the first resource "You need to have a good understanding of embedded system development and should be proficient in C programming". This is the rub to my request as I am not proficient in C. The link you've provided appears to cover most of the information that would be needed to teach one's self the basics of embedded programming. Still on the hunt for what is essentially an arduino button debounce through the lens of the STM32F7 and IDE. Maybe this is the info you sent, I am working my way through the material now.

https://www.arduino.cc/en/tutorial/debounce

RMcn.1
Associate II

Is there example code for how to light an on board LED with the USER Button?

Shirley.Ye
ST Employee

you can see the code below. And first you need to configure the user button as input interrupt. And configure the IRQ handler.

void EXTI4_15_IRQHandler(void)

{

 HAL_GPIO_EXTI_IRQHandler(DETECT_PIN);

 if(BlinkSpeed == 2)

  BlinkSpeed = 0;

 else

  BlinkSpeed ++;

  

}

  LEDs_Init();

  __GPIOC_CLK_ENABLE();

  GPIO_InitTypeDef GPIO_InitStruct;

  /* Configure Button pin as input */

  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Pin = GPIO_PIN_13;

  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0x0F, 0x0F);

  HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

  BlinkSpeed = 0;

  while(1)

  {

   /* Test on blink speed */

   if(BlinkSpeed == 0)

   {

    LD4_TOGGLE();

    HAL_Delay(50);

   }

   else if(BlinkSpeed == 1)

   {

    LD4_TOGGLE();

    HAL_Delay(500); 

   }

   else if(BlinkSpeed == 2)

   {

    LD4_TOGGLE();

    HAL_Delay(100);

   }

  }

Manny
Associate III

The first thing that you should do is setting up you environment(IAR Workbench, Keil or stmcubemx), then you can toggle an on board led to see you code work(use some debug point to see that it reaches that point).

I don't use HAL Lib, but you can find example code for it,

The code in the above link most likely will not work for your case, but I hope it will provide you with some useful knowledge.

https://stm32f4-discovery.net/2014/04/stm32f429-discovery-gpio-tutorial-with-onboard-leds-and-button/