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. | ||
| + | |||
| + | /*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 | ||
| + | } | ||
[[Image:BAM210_PhotoInt.jpeg|center|]] | [[Image:BAM210_PhotoInt.jpeg|center|]] | ||
Revision as of 14:39, 14 August 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.
/*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
}


