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 // create PWM objects for leds 00004 PwmOut led1(LED1),led2(LED2),led3(LED3),led4(LED4); 00005 00006 // start que 00007 float a=0.25f,b=0,c=-0.25f,d=-0.5f; 00008 00009 // init down or uplight 00010 int aa=0,bb=0,cc=0,dd=0; 00011 00012 void blinky(int &dir,float &val){ 00013 if (val>=0.5){ 00014 dir=1; 00015 } else if (val<-1) { 00016 dir=0; 00017 } 00018 00019 if (dir==0) { 00020 val+=0.025f; 00021 } else { 00022 val-=0.025f; 00023 }; 00024 } 00025 00026 int globaldir=0; 00027 int cnt=0; 00028 int main() { 00029 while (1) { 00030 // Toggle directions every 3rd cycle 00031 if ((!aa && d<-1) || (!dd && a<-1)) { 00032 cnt+=1; 00033 if ( cnt>(3-1) ) { 00034 cnt=0; 00035 if (!globaldir) { 00036 d=0.00f,c=-0.25f,b=-0.50f,a=-0.75f; 00037 } else { 00038 a=0.00f,b=-0.25f,c=-0.50f,d=-0.75f; 00039 } 00040 aa=0,bb=0,cc=0,dd=0; 00041 globaldir=(!globaldir); 00042 } 00043 } 00044 00045 // calc led-values 00046 blinky(aa,a); 00047 blinky(bb,b); 00048 blinky(cc,c); 00049 blinky(dd,d); 00050 00051 // set leds 00052 led1 = a; 00053 led2 = b; 00054 led3 = c; 00055 led4 = d; 00056 00057 wait(0.010); 00058 } 00059 }
Generated on Wed Aug 17 2022 05:18:48 by
1.7.2