Skip to content

Instantly share code, notes, and snippets.

@rallicknom
Last active July 25, 2016 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rallicknom/a9a942b77098ce8ce853cd90288e5f22 to your computer and use it in GitHub Desktop.
Save rallicknom/a9a942b77098ce8ce853cd90288e5f22 to your computer and use it in GitHub Desktop.
Mbed code for blinking an LED on F030R8
// This code works as blinky. It toggles the LED every 1 second (not 2 second as expected from the code)
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1; // LED is ON
wait(1); // 1 sec
wait(1); // 1 sec
myled = 0; // LED is OFF
wait(1); // 1 sec
wait(1); // 1 sec
}
}
// Above code gives me an output as expected from the code below:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1; // LED is ON
wait(1); // 1 sec
//wait(1); // 1 sec
myled = 0; // LED is OFF
wait(1); // 1 sec
//wait(1); // 1 sec
}
}
// Another issue that I noted was that timings were a bit off. The LED wasn't blinking at exactly 1 s.
//It was more like 0.9 second or so. Maybe due to inaccurate internal oscillator.
// Second code leaves the LED permanently ON.
//***********************
// I tried to print some debug info to get an idea of what was happening. Here is the code:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1; // LED is ON
wait(1); // 1 sec
printf("0");
myled = 0; // LED is OFF
wait(1); // 1 sec
printf("1");
}
}
// Instead of getting 0 (delay) 1 (delay) 0 (delay) (1) ..... etc, I am getting 01 (delay) 01 (delay) ...
// OR 10 (delay) 10 (delay) (10)...
// It means one wait function misses out during code execution, for some reason.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment