Rob Toulson / Mbed 2 deprecated PE_03-04_PhotoInterrupter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor
00002                                                                        */
00003 #include "mbed.h"
00004 DigitalOut redled(p5);
00005 DigitalIn  opto_switch(p12);
00006 
00007 int main()
00008 {
00009     while(1) {
00010         if (opto_switch==1)           //input = 1 if beam interrupted
00011             redled = 1;                 //switch led on if beam interrupted
00012 
00013         else
00014             redled = 0;                 //led off if no interruption
00015     }                               //end of while
00016 }