 |
Arduino Core for STM32
1.0
|
- LED blinking
#define LED_PIN PA1 //LED is connected to pin PA1
void app(void)
{
while (1)
{
}
}
- NonBlocking LED blinking
#define LED_PIN PA1 //LED is connected to pin PA1
unsigned long next_toggle_millis = 0;
void app(void)
{
while (1)
{
if(next_toggle_millis <=
millis()){
next_toggle_millis =
millis() + 500;
}
}
}
- LED blinking with button
#define LED_PIN PA1 //LED is connected to pin PA1
#define BUTTON_PIN PA2 //button is connected to pin PA2
void app(void)
{
while (1)
{
}
}
- LED blinking with button using interrupts
#define LED_PIN PA1 //LED is connected to pin PA1
#define BUTTON_PIN PA2 //button is connected to pin PA2
void buttonTouchedHandler(){
}
void app(void)
{
while (1)
{
}
}
- Note
- Those examples works only with c++, but STM32CubeIDE does not allow you to change main.c to main.cpp, so you have to create own c++ file, and include it in main.h. In your cpp file create function, that will be called in main() function. In this case, function name is app() and is called in main() function between tags USER CODE BEGIN 2 and USER CODE END 2.
- See also
- Wirish documentation
-
wirish.h
-
WiringPinMode
#define millis()
Returns the number of milliseconds passed since the STM board began running the current program.
Definition: wirish.h:851
#define delay(millis)
Pauses the program for the amount of time (in milliseconds) specified as parameter.
Definition: wirish.h:860
#define CHANGE
GPIO interrupt will be triggered when pin state change.
Definition: wirish.h:1018
@ OUTPUT
Basic digital output: when the pin is HIGH, the voltage is held at +3.3v (Vcc) and when it is LOW,...
Definition: wirish.h:467
uint16_t digitalRead(GPIO_TypeDef *GPIOx, uint16_t PPin)
Reads state of pin or multiple pins.
Definition: wirish.h:636
@ INPUT_PULLDOWN
The state of the pin in this mode is reported the same way as with INPUT, but the pin voltage is gent...
Definition: wirish.h:508
This file contains basic (Arduino like) GPIO manipulation functions, delay, random,...
uint8_t pinMode(GPIO_TypeDef *GPIOx, uint16_t PPin, WiringPinMode mode, uint32_t speed)
Sets mode of selected pin.
Definition: wirish.cpp:250
void digitalWrite(GPIO_TypeDef *GPIOx, uint16_t PPin, bool val)
Writes new state to pin or multiple pins.
Definition: wirish.h:626
void digitalToggle(GPIO_TypeDef *GPIOx, uint16_t PPin)
Toggles pin state.
Definition: wirish.h:645
int8_t attachInterrupt(uint8_t Pin, std::function< void(void)>, int mode)
Attaches interrupt to selected pin.
Definition: wirish.cpp:669