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:23:38 2012 +0000
Revision:
0:473ce61a7de9
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:473ce61a7de9 1 /*Program Example 3.3: Flashes one of two LEDs, depending on the state of a 2-way switch
robt 0:473ce61a7de9 2 */
robt 0:473ce61a7de9 3 #include "mbed.h"
robt 0:473ce61a7de9 4 DigitalOut redled(p5);
robt 0:473ce61a7de9 5 DigitalOut greenled(p6);
robt 0:473ce61a7de9 6 DigitalIn switchinput(p7);
robt 0:473ce61a7de9 7 int main()
robt 0:473ce61a7de9 8 {
robt 0:473ce61a7de9 9 while(1) {
robt 0:473ce61a7de9 10 if (switchinput==1) { //test value of switchinput
robt 0:473ce61a7de9 11 //execute following block if switchinput is 1
robt 0:473ce61a7de9 12 greenled = 0; //green led is off
robt 0:473ce61a7de9 13 redled = 1; // flash red led
robt 0:473ce61a7de9 14 wait(0.2);
robt 0:473ce61a7de9 15 redled = 0;
robt 0:473ce61a7de9 16 wait(0.2);
robt 0:473ce61a7de9 17 } //end of if
robt 0:473ce61a7de9 18 else { //here if switchinput is 0
robt 0:473ce61a7de9 19 redled = 0; //red led is off
robt 0:473ce61a7de9 20 greenled = 1; // flash green led
robt 0:473ce61a7de9 21 wait(0.2);
robt 0:473ce61a7de9 22 greenled = 0;
robt 0:473ce61a7de9 23 wait(0.2);
robt 0:473ce61a7de9 24 } //end of else
robt 0:473ce61a7de9 25 } //end of while(1)
robt 0:473ce61a7de9 26 } //end of main
robt 0:473ce61a7de9 27