/ Mbed 2 deprecated LAB1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 DigitalOut led[]= {PA_5,PA_10,PB_3,PB_5,PA_8,PA_9,PC_7,PA_6};
00003 
00004 DigitalIn   myB1(USER_BUTTON);
00005 DigitalIn myB2(D5);
00006 DigitalIn myB3(D6);
00007 Timer t;
00008 int n;
00009 // main() runs in its own thread in the OS
00010 int main()
00011 {
00012     while(true)
00013 
00014     {
00015 
00016         if(myB1==0) {
00017             n=1;
00018             while(n==1) {
00019                 for(int i=0; i<8; i++) {
00020                     led[i] = 1;
00021                     wait_ms(100);
00022 
00023                 }
00024                 for(int i=8; i>=0; i--) {
00025                     led[i] = 0;
00026                     wait_ms(100);
00027                 }
00028                 if(myB2==1||myB3== 1) {
00029                     n = 0;
00030                 } else {
00031                     n = n;
00032                 }
00033             }
00034         } else if(myB2==1) {
00035             n = 2;
00036             while(n==2) {
00037                 for(int i=0; i<8; i+=2) {
00038                     led[i] = 1;
00039                     wait_ms(100);
00040                 }
00041                 for(int i=8; i>=0; i-=2) {
00042                     led[i] = 0;
00043                     wait_ms(100);
00044                 }
00045                 if(myB1==0||myB3== 1) {
00046                     n = 0;
00047                 } else {
00048                     n = n;
00049                 }
00050             }
00051         } else if(myB3==1) {
00052             n = 3;
00053             while(n==3) {
00054                 for(int i=0; i<8; i++) {
00055                     led[i] = 1;
00056                     wait_ms(100);
00057                     led[i] = 0;
00058                 }
00059                 for(int i=8; i>0; i--) {
00060                     led[i] = 0;
00061                     wait_ms(100);
00062                     led[i] = 1;
00063                     wait_ms(100);
00064                     led[i] = 0;
00065                     wait_ms(100);
00066                 }
00067             
00068             if(myB1==0||myB2== 1) {
00069                 n = 0;
00070             } else {
00071                 n = n;
00072             }
00073         }}
00074     }
00075 }