by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Committer:
robt
Date:
Fri Aug 31 15:21:31 2012 +0000
Revision:
0:1ec908c46d5f
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:1ec908c46d5f 1 /*Program Example 3.1: Demonstrates use of while loops. No external connection required
robt 0:1ec908c46d5f 2 */
robt 0:1ec908c46d5f 3 #include "mbed.h"
robt 0:1ec908c46d5f 4 DigitalOut myled(LED1);
robt 0:1ec908c46d5f 5 DigitalOut yourled(LED4);
robt 0:1ec908c46d5f 6
robt 0:1ec908c46d5f 7 int main()
robt 0:1ec908c46d5f 8 {
robt 0:1ec908c46d5f 9 char i=0; //declare variable i, and set to 0
robt 0:1ec908c46d5f 10 while(1) { //start endless loop
robt 0:1ec908c46d5f 11 while(i<10) { //start first conditional while loop
robt 0:1ec908c46d5f 12 myled = 1;
robt 0:1ec908c46d5f 13 wait(0.2);
robt 0:1ec908c46d5f 14 myled = 0;
robt 0:1ec908c46d5f 15 wait(0.2);
robt 0:1ec908c46d5f 16 i = i+1; //increment i
robt 0:1ec908c46d5f 17 } //end of first conditional while loop
robt 0:1ec908c46d5f 18 while(i>0) { //start second conditional loop
robt 0:1ec908c46d5f 19 yourled = 1;
robt 0:1ec908c46d5f 20 wait(0.2);
robt 0:1ec908c46d5f 21 yourled = 0;
robt 0:1ec908c46d5f 22 wait(0.2);
robt 0:1ec908c46d5f 23 i = i-1;
robt 0:1ec908c46d5f 24 }
robt 0:1ec908c46d5f 25 } //end infinite loop block
robt 0:1ec908c46d5f 26 } //end of main
robt 0:1ec908c46d5f 27