03-04 PhotoInterrupter
From Manuals
(Difference between revisions)
| Line 1: | Line 1: | ||
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. | 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. | ||
| + | [[Image:BAM210_03_04_SCH.png|center|alt=BAM210|frame|<div align="center">'''Schematic for example 03-04''']] | ||
| + | |||
| + | <div style="text-align: left;"> | ||
/*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor | /*Program Example 3.4: Simple program to test KTIR slotted optosensor. Switches an LED according to state of sensor | ||
*/ | */ | ||
| Line 18: | Line 22: | ||
} | } | ||
| + | The following image shows the built circuit. | ||
[[Image:BAM210_PhotoInt.jpeg|center|]] | [[Image:BAM210_PhotoInt.jpeg|center|]] | ||
| - | |||
| - | |||
| - | |||
Revision as of 15:57, 17 September 2014
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.
/*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.


