Your First Program
The first as always we will try to blink an LED. Open a text Notepad and make a new document as Blink.cpp file. Save this file inside the stm32f4 folder. Contents of this file is as follows
#include <WProgram.h> uint32_t previousMillis = 0; uint32_t interval = 1000; int ledState = LOW; int ledPin = 59; void setup() { pinMode(ledPin, OUTPUT); } void loop(void) { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; if (ledState == LOW) ledState = HIGH; else ledState = LOW; digitalWrite(ledPin, ledState); } }
As you can see, the program is straightforward.
In void setup() , which is run only once in the whole program we set up the Ledpin which is defined as pin number 59 (refers to PORTD pin 12) (for various pin details refer to STM32V1F4 inside the stm32f4/wirish/ folder .
We set this pin as output.
In the loop program which is just like a while(1) function,
We toggle the LED. As can be seen, millis() function returns the milliseconds enacted from the beginning of the program. This means that if the program started at 0, and ran for 10 seconds and after that you called the millis() function, it would return the value of 10000. Keeping this as the reference we check if one second has passed by defining the INTERVAL as 1000. Once a second has passed by we output the toggled state by using the digitalWrite() function as shown.
Now go on forward to compile and send your program.
In void setup() , which is run only once in the whole program we set up the Ledpin which is defined as pin number 59 (refers to PORTD pin 12) (for various pin details refer to STM32V1F4 inside the stm32f4/wirish/ folder .
We set this pin as output.
In the loop program which is just like a while(1) function,
We toggle the LED. As can be seen, millis() function returns the milliseconds enacted from the beginning of the program. This means that if the program started at 0, and ran for 10 seconds and after that you called the millis() function, it would return the value of 10000. Keeping this as the reference we check if one second has passed by defining the INTERVAL as 1000. Once a second has passed by we output the toggled state by using the digitalWrite() function as shown.
Now go on forward to compile and send your program.