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:24:00 2012 +0000
Revision:
0:de142f1cc7a2
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:de142f1cc7a2 1 /*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor
robt 0:de142f1cc7a2 2 */
robt 0:de142f1cc7a2 3 #include "mbed.h"
robt 0:de142f1cc7a2 4 DigitalOut redled(p5);
robt 0:de142f1cc7a2 5 DigitalIn opto_switch(p12);
robt 0:de142f1cc7a2 6
robt 0:de142f1cc7a2 7 int main()
robt 0:de142f1cc7a2 8 {
robt 0:de142f1cc7a2 9 while(1) {
robt 0:de142f1cc7a2 10 if (opto_switch==1) //input = 1 if beam interrupted
robt 0:de142f1cc7a2 11 redled = 1; //switch led on if beam interrupted
robt 0:de142f1cc7a2 12
robt 0:de142f1cc7a2 13 else
robt 0:de142f1cc7a2 14 redled = 0; //led off if no interruption
robt 0:de142f1cc7a2 15 } //end of while
robt 0:de142f1cc7a2 16 }