RC5 compatible receiver class, interrupt driven

Dependencies:   mbed

Committer:
pwheels
Date:
Mon Feb 28 08:52:01 2011 +0000
Revision:
0:e3f62f54fa40
replaces RC5_Receiver, has been removed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pwheels 0:e3f62f54fa40 1 /*
pwheels 0:e3f62f54fa40 2 Copyright (c) 2011 Pro-Serv
pwheels 0:e3f62f54fa40 3
pwheels 0:e3f62f54fa40 4 Permission is hereby granted, free of charge, to any person obtaining a copy
pwheels 0:e3f62f54fa40 5 of this software and associated documentation files (the "Software"), to deal
pwheels 0:e3f62f54fa40 6 in the Software without restriction, including without limitation the rights
pwheels 0:e3f62f54fa40 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pwheels 0:e3f62f54fa40 8 copies of the Software, and to permit persons to whom the Software is
pwheels 0:e3f62f54fa40 9 furnished to do so, subject to the following conditions:
pwheels 0:e3f62f54fa40 10
pwheels 0:e3f62f54fa40 11 The above copyright notice and this permission notice shall be included in
pwheels 0:e3f62f54fa40 12 all copies or substantial portions of the Software.
pwheels 0:e3f62f54fa40 13
pwheels 0:e3f62f54fa40 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pwheels 0:e3f62f54fa40 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pwheels 0:e3f62f54fa40 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pwheels 0:e3f62f54fa40 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pwheels 0:e3f62f54fa40 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pwheels 0:e3f62f54fa40 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pwheels 0:e3f62f54fa40 20 THE SOFTWARE.
pwheels 0:e3f62f54fa40 21
pwheels 0:e3f62f54fa40 22 Usage and assumptions:
pwheels 0:e3f62f54fa40 23 Based on TSOP 1738 IR device, Vcc to 5Volt, Gnd to Gnd, Out has pull-up of 10K
pwheels 0:e3f62f54fa40 24 to Vcc and Out has diode (Cathode to Out) connected to pin (p16) (Anode to p16)
pwheels 0:e3f62f54fa40 25 and pin (p16) has mode PullUp
pwheels 0:e3f62f54fa40 26
pwheels 0:e3f62f54fa40 27 This will allow a "standard" RC5 device to be used to read it transmitted codes.
pwheels 0:e3f62f54fa40 28 Still work in progress (in due time) to add newer rc6 devices
pwheels 0:e3f62f54fa40 29
pwheels 0:e3f62f54fa40 30 Excellent source on RC5 protocol: http://www.ustr.net/infrared/infrared1.shtml
pwheels 0:e3f62f54fa40 31 */
pwheels 0:e3f62f54fa40 32
pwheels 0:e3f62f54fa40 33 #include "mbed.h"
pwheels 0:e3f62f54fa40 34 #include "RC5Detect.h"
pwheels 0:e3f62f54fa40 35
pwheels 0:e3f62f54fa40 36 RC5Detect rc5 ( p16, PullUp);
pwheels 0:e3f62f54fa40 37
pwheels 0:e3f62f54fa40 38 DigitalOut led1( LED1 );
pwheels 0:e3f62f54fa40 39
pwheels 0:e3f62f54fa40 40 int main() {
pwheels 0:e3f62f54fa40 41
pwheels 0:e3f62f54fa40 42 //rc5.setAssertValue( 0 );
pwheels 0:e3f62f54fa40 43 rc5.setDelaySample(4820);
pwheels 0:e3f62f54fa40 44 rc5.setIntervalSample(1778);
pwheels 0:e3f62f54fa40 45
pwheels 0:e3f62f54fa40 46 while(1) {
pwheels 0:e3f62f54fa40 47 if (rc5.getReadyState()) {
pwheels 0:e3f62f54fa40 48 printf("RC5 received, address = %d, command = %d\n", rc5.getRC5Address(), rc5.getRC5Command());
pwheels 0:e3f62f54fa40 49 rc5.setReadyState(0);
pwheels 0:e3f62f54fa40 50 }
pwheels 0:e3f62f54fa40 51 led1 = 1;
pwheels 0:e3f62f54fa40 52 wait(0.2);
pwheels 0:e3f62f54fa40 53 led1 = 0;
pwheels 0:e3f62f54fa40 54 wait(0.2);
pwheels 0:e3f62f54fa40 55 }
pwheels 0:e3f62f54fa40 56 }