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 00002 // show a "progress bar" using the four blue LED 00003 // 00004 // by (85) 00005 00006 #include "mbed.h" 00007 00008 PwmOut led1(LED1); 00009 PwmOut led2(LED2); 00010 PwmOut led3(LED3); 00011 PwmOut led4(LED4); 00012 00013 float done = 0.0; 00014 int mode = 0; 00015 00016 float zerolim(float a) { 00017 // returns a^2 for a >= 0 00018 return a < 0. ? 0. : a*a; 00019 } 00020 00021 int main() { 00022 while (1) { 00023 if (!(mode & 1)) { 00024 done += 0.01; 00025 if (done >= 1.1) 00026 ++mode; 00027 } 00028 if (mode & 1) { 00029 done -= 0.01; 00030 if (done <= -0.1) 00031 ++mode; 00032 } 00033 /* 00034 // interesting, but not intended 00035 led1 = (done*4)*(done*4); 00036 led2 = (done*4-1)*(done*4-1); 00037 led3 = (done*4-2)*(done*4-2); 00038 led4 = (done*4-3)*(done*4-3); 00039 */ 00040 /* 00041 // linear 00042 led1 = done*4; 00043 led2 = done*4-1; 00044 led3 = done*4-2; 00045 led4 = done*4-3; 00046 */ 00047 led1 = zerolim(done*4); 00048 led2 = zerolim(done*4-1); 00049 led3 = zerolim(done*4-2); 00050 led4 = zerolim(done*4-3); 00051 wait(0.01); 00052 } 00053 }
Generated on Sun Jul 31 2022 19:55:32 by
1.7.2