Rob Toulson / Mbed 2 deprecated PE_03-01_WhileLoop

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Program Example 3.1: Demonstrates use of while loops. No external connection required
00002                                                                                */
00003 #include "mbed.h"
00004 DigitalOut myled(LED1);
00005 DigitalOut yourled(LED4);
00006 
00007 int main()
00008 {
00009     char i=0;         //declare variable i, and set to 0
00010     while(1) {        //start endless loop
00011         while(i<10) {     //start first conditional while loop
00012             myled = 1;
00013             wait(0.2);
00014             myled = 0;
00015             wait(0.2);
00016             i = i+1;         //increment i
00017         }                  //end of first conditional while loop
00018         while(i>0) {       //start second conditional loop
00019             yourled = 1;
00020             wait(0.2);
00021             yourled = 0;
00022             wait(0.2);
00023             i = i-1;
00024         }
00025     }                  //end infinite loop block
00026 }                    //end of main
00027