svn / mbed / trunk / DigitalIn.h

Revision 29, 2.1 kB (checked in by emilmont, 6 months ago)

New Libraries 11.11

Line 
1/* mbed Microcontroller Library - DigitalIn
2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
3 */ 
4 
5#ifndef MBED_DIGITALIN_H
6#define MBED_DIGITALIN_H
7
8#include "platform.h"
9#include "PinNames.h"
10#include "PeripheralNames.h"
11#include "Base.h"
12
13namespace mbed {
14
15/* Class: DigitalIn
16 *  A digital input, used for reading the state of a pin
17 *
18 * Example:
19 * > // Flash an LED while a DigitalIn is true
20 * >
21 * > #include "mbed.h"
22 * >
23 * > DigitalIn enable(p5);
24 * > DigitalOut led(LED1);
25 * >
26 * > int main() {
27 * >     while(1) {
28 * >         if(enable) {
29 * >             led = !led;
30 * >         }
31 * >         wait(0.25);
32 * >     }
33 * > }
34 */
35class DigitalIn : public Base {
36
37public:
38
39    /* Constructor: DigitalIn
40     *  Create a DigitalIn connected to the specified pin
41     *
42     * Variables:
43     *  pin - DigitalIn pin to connect to
44     *  name - (optional) A string to identify the object
45     */
46    DigitalIn(PinName pin, const char *name = NULL);
47
48    /* Function: read
49     *  Read the input, represented as 0 or 1 (int)
50     *
51     * Variables:
52     *  returns - An integer representing the state of the input pin,
53     *      0 for logical 0 and 1 for logical 1
54     */
55    int read() {
56#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
57        return ((_gpio->FIOPIN & _mask) ? 1 : 0);
58#elif defined(TARGET_LPC11U24)
59        return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0);
60#endif
61    }
62
63
64    /* Function: mode
65     *  Set the input pin mode
66     *
67     * Variables:
68     *  mode - PullUp, PullDown, PullNone, OpenDrain
69     */
70    void mode(PinMode pull);
71   
72#ifdef MBED_OPERATORS   
73    /* Function: operator int()
74     *  An operator shorthand for <read()>
75     */
76    operator int() {
77        return read();
78    }
79
80#endif
81
82#ifdef MBED_RPC
83    virtual const struct rpc_method *get_rpc_methods();
84    static struct rpc_class *get_rpc_class();
85#endif
86
87protected:
88
89    PinName             _pin;
90#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
91    LPC_GPIO_TypeDef    *_gpio;
92#elif defined(TARGET_LPC11U24)
93    int _index;
94#endif
95    uint32_t            _mask;
96
97};
98
99} // namespace mbed
100
101#endif
102
Note: See TracBrowser for help on using the browser.