RF link test program using low cost modules from Sparkfun See http://mbed.org/users/4180_1/notebook/ir-and-rf-remote-controls/
main.cpp@0:a4f7b521f1ce, 2012-02-10 (annotated)
- Committer:
- 4180_1
- Date:
- Fri Feb 10 02:33:58 2012 +0000
- Revision:
- 0:a4f7b521f1ce
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:a4f7b521f1ce | 1 | #include "mbed.h" |
4180_1 | 0:a4f7b521f1ce | 2 | |
4180_1 | 0:a4f7b521f1ce | 3 | Serial pc(USBTX, USBRX); // tx, rx |
4180_1 | 0:a4f7b521f1ce | 4 | Serial device(p9, p10); // tx, rx |
4180_1 | 0:a4f7b521f1ce | 5 | DigitalOut myled1(LED1); |
4180_1 | 0:a4f7b521f1ce | 6 | DigitalOut myled2(LED2); |
4180_1 | 0:a4f7b521f1ce | 7 | //RF link demo using low-cost Sparkfun RF transmitter and receiver modules |
4180_1 | 0:a4f7b521f1ce | 8 | //LEDs indicate link activity |
4180_1 | 0:a4f7b521f1ce | 9 | //Characters typed in PC terminal windows will echo back using RF link |
4180_1 | 0:a4f7b521f1ce | 10 | int main() { |
4180_1 | 0:a4f7b521f1ce | 11 | char temp=0; |
4180_1 | 0:a4f7b521f1ce | 12 | device.baud(2400); |
4180_1 | 0:a4f7b521f1ce | 13 | while (1) { |
4180_1 | 0:a4f7b521f1ce | 14 | |
4180_1 | 0:a4f7b521f1ce | 15 | //RF Transmit Code |
4180_1 | 0:a4f7b521f1ce | 16 | if (pc.readable()==0) { |
4180_1 | 0:a4f7b521f1ce | 17 | myled1 = 1; |
4180_1 | 0:a4f7b521f1ce | 18 | //Send 10101010 pattern when idle to keep receiver in sync and locked to transmitter |
4180_1 | 0:a4f7b521f1ce | 19 | //When receiver loses the sync lock (Around 30MS with no data change seen) it starts sending out noise |
4180_1 | 0:a4f7b521f1ce | 20 | device.putc(0xAA); |
4180_1 | 0:a4f7b521f1ce | 21 | myled1 = 0; |
4180_1 | 0:a4f7b521f1ce | 22 | } else |
4180_1 | 0:a4f7b521f1ce | 23 | //Send out the real data whenever a key is typed |
4180_1 | 0:a4f7b521f1ce | 24 | device.putc(pc.getc()); |
4180_1 | 0:a4f7b521f1ce | 25 | |
4180_1 | 0:a4f7b521f1ce | 26 | //RF Receive Code |
4180_1 | 0:a4f7b521f1ce | 27 | if (device.readable()) { |
4180_1 | 0:a4f7b521f1ce | 28 | myled2 = 1; |
4180_1 | 0:a4f7b521f1ce | 29 | temp=device.getc(); |
4180_1 | 0:a4f7b521f1ce | 30 | //Ignore Sync pattern and do not pass on to PC |
4180_1 | 0:a4f7b521f1ce | 31 | if (temp!=0xAA) pc.putc(temp); |
4180_1 | 0:a4f7b521f1ce | 32 | myled2 = 0; |
4180_1 | 0:a4f7b521f1ce | 33 | } |
4180_1 | 0:a4f7b521f1ce | 34 | } |
4180_1 | 0:a4f7b521f1ce | 35 | } |