SEARCH
TOOLBOX
LANGUAGES
modified on 17 September 2014 at 15:57 ••• 21,971 views

03-04 PhotoInterrupter

From Manuals

Revision as of 15:57, 17 September 2014 by Support (Talk | contribs)
Jump to: navigation, search

A simple program to test KTIR slotted optosensor. It switches an LED according to state of sensor. The LED is connected to D0 of J9 and the optosenser is connected to D2.

Please see schematic below for further details.

BAM210
Schematic for example 03-04
/*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor
                                                                       */
#include "mbed.h"
DigitalOut redled(D0);
DigitalIn  opto_switch(D2);

int main()
{
    while(1) {
        if (opto_switch==1)           //input = 1 if beam interrupted
            redled = 1;                 //switch led on if beam interrupted 

        else
            redled = 0;                 //led off if no interruption
    }                               //end of while
}

The following image shows the built circuit.