Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 00003 PwmOut mypwm(PWM_OUT); 00004 00005 DigitalOut myled(LED1); 00006 00007 #define UP 1 00008 #define DOWN 2 00009 00010 int main() { 00011 00012 uint8_t i; 00013 uint8_t count_dir; 00014 00015 00016 mypwm.period_ms(10); 00017 mypwm.pulsewidth_ms(1); 00018 00019 printf("pwm set to %.2f %%\n", mypwm.read() * 100); 00020 00021 count_dir = UP; 00022 while(1) { 00023 myled = !myled; 00024 for(i = 0; i < 10; i++ ) 00025 { 00026 wait(0.1); 00027 if(count_dir == UP) 00028 { 00029 mypwm = mypwm + 0.01; 00030 if(mypwm == 1.00) // if hit one, start counting down 00031 { 00032 count_dir = DOWN; 00033 } 00034 } 00035 else if(count_dir == DOWN) 00036 { 00037 mypwm = mypwm - 0.01; 00038 if(mypwm == 0.0) // if hit zero, start counting up 00039 { 00040 count_dir = UP; 00041 } 00042 } 00043 00044 } 00045 printf("pwm set to %.2f %%\n\r", mypwm.read() * 100); 00046 } 00047 }
Generated on Sun Jul 17 2022 20:03:31 by
 1.7.2