SEARCH
TOOLBOX
LANGUAGES
modified on 14 August 2014 at 14:39 ••• 21,981 views

03-04 PhotoInterrupter

From Manuals

Revision as of 14:39, 14 August 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.

/*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
}


BAM210
Schematic for example 03-04