Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
Templete code does not work in my board
<< code >>
- include "mbed.h" DigitalOut myled(LED1); int main() { while(1) { myled = 1; LED is ON wait(1); 200 ms myled = 0; LED is OFF wait(1); 1 sec } } << /code >>
The code above works fine but the following not works. I do not know why.
Can anyone give a hint?
<< code >> From mbed templete
- include "mbed.h" PwmOut mypwm(PWM_OUT); DigitalOut myled(LED1); int main() { mypwm.period_ms(10); mypwm.pulsewidth_ms(1); printf("pwm set to %.2f %%\n", mypwm.read() * 100); while(1) { myled = !myled; wait(1); } } << /code >>
2 Answers
9 years, 2 months ago.
Try the following As you do not define which serial port you are writing to or the BAUD rate If you dont use Serial class your code compiles and writes to the USB/Serial on the ST you just need to use PuTTY, teraterm or same to monitor
#include "mbed.h" PwmOut mypwm(PWM_OUT);// PWM/D3 DigitalOut myled(LED1); Serial pc(USBTX,USBRX); int main() { pc.baud(115200); mypwm.period_ms(10); mypwm.pulsewidth_ms(1); printf("pwm set to %.2f %%\n", mypwm.read() * 100); //or to be more definative pc.printf("pwm set to %.2f %%\n", mypwm.read() * 100); while(1) { myled = !myled; wait(1); } }
regards
9 years, 1 month ago.
You have not defined a pin for PWM out.
If you are using the LPC1768 - Blue MBED, then the LED's are also PWM capable !
{ myled = !myled; wait (1); }
is fine, in one or two lines :)
ceri
Define "not works". It doesn't compile (if so what is the error)? It doesn't run? Do you get anything out of the serial port?
Also please use
posted by Andy A 01 Sep 2015<<code>> and <</code>>
to correctly format any sections of code that you post. The preview button is your friend.