Nobuki HIRAMINE
/
irreceiver
IR Receiver
main.cpp@0:883a77e07ad5, 2012-12-01 (annotated)
- Committer:
- nobuki
- Date:
- Sat Dec 01 13:23:21 2012 +0000
- Revision:
- 0:883a77e07ad5
Version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nobuki | 0:883a77e07ad5 | 1 | #include "mbed.h" |
nobuki | 0:883a77e07ad5 | 2 | |
nobuki | 0:883a77e07ad5 | 3 | DigitalIn g_dpinIrReceiver(p30); |
nobuki | 0:883a77e07ad5 | 4 | |
nobuki | 0:883a77e07ad5 | 5 | Serial g_serial(USBTX, USBRX); |
nobuki | 0:883a77e07ad5 | 6 | |
nobuki | 0:883a77e07ad5 | 7 | int main() |
nobuki | 0:883a77e07ad5 | 8 | { |
nobuki | 0:883a77e07ad5 | 9 | g_serial.baud(115200); |
nobuki | 0:883a77e07ad5 | 10 | |
nobuki | 0:883a77e07ad5 | 11 | Timer timer; |
nobuki | 0:883a77e07ad5 | 12 | timer.start(); |
nobuki | 0:883a77e07ad5 | 13 | int iMicroSec_prev = timer.read_us(); |
nobuki | 0:883a77e07ad5 | 14 | int iState_prev = 1; |
nobuki | 0:883a77e07ad5 | 15 | while(1) |
nobuki | 0:883a77e07ad5 | 16 | { |
nobuki | 0:883a77e07ad5 | 17 | int iState = g_dpinIrReceiver; |
nobuki | 0:883a77e07ad5 | 18 | if( iState != iState_prev ) |
nobuki | 0:883a77e07ad5 | 19 | { |
nobuki | 0:883a77e07ad5 | 20 | iState_prev = iState; |
nobuki | 0:883a77e07ad5 | 21 | int iMicroSec = timer.read_us(); |
nobuki | 0:883a77e07ad5 | 22 | g_serial.printf( "%d, ", iMicroSec - iMicroSec_prev ); |
nobuki | 0:883a77e07ad5 | 23 | iMicroSec_prev = iMicroSec; |
nobuki | 0:883a77e07ad5 | 24 | } |
nobuki | 0:883a77e07ad5 | 25 | } |
nobuki | 0:883a77e07ad5 | 26 | } |