![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
0720_Lab1
Dependencies: mbed
main.cpp
- Committer:
- chinetion
- Date:
- 2015-10-15
- Revision:
- 0:f17d9dc54c1d
File content as of revision 0:f17d9dc54c1d:
#include "mbed.h" DigitalOut led[] = {D2,D3,D4,D5,D6,D7,D8,D9}; DigitalIn In[] = {D10,D11,D12}; double speed=0.1; int pat = 1,tog=0; void check(){ tog=0; if(In[0]){pat++;tog=1;} if(In[1])speed+=0.02; if(In[2])speed-=0.02; if(speed<=0.02)speed=0.02; else if(speed>=1)speed=1; if(pat>3)pat=1; } int main(){ while(1){ if(pat==1){ for(int x=0;x<=7;x++){ led[x]=1; wait(speed); led[x]=0; check();if(tog==1)break; } } if(pat==2){ for(int x=0;x<=7;x++){ led[x]=1; wait(speed); check();if(tog==1)break; } for(int x=0;x<=7;x++){ led[x]=0; wait(speed); check();if(tog==1)break; } } if(pat==3){ for(int x=0;x<=3;x++){ led[x]=1; led[7-x]=1; wait(speed); check();if(tog==1)break; } for(int x=3;x>=0;x--){ led[x]=0; led[7-x]=0; wait(speed); check();if(tog==1)break; } } } }