Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
mbed/DigitalIn.h@3:5dc0023e6284, 2014-01-31 (annotated)
- Committer:
- wyunreal
- Date:
- Fri Jan 31 23:19:28 2014 +0000
- Revision:
- 3:5dc0023e6284
First approach of EthernetService class
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wyunreal | 3:5dc0023e6284 | 1 | /* mbed Microcontroller Library - DigitalIn |
| wyunreal | 3:5dc0023e6284 | 2 | * Copyright (c) 2006-2009 ARM Limited. All rights reserved. |
| wyunreal | 3:5dc0023e6284 | 3 | * sford |
| wyunreal | 3:5dc0023e6284 | 4 | */ |
| wyunreal | 3:5dc0023e6284 | 5 | |
| wyunreal | 3:5dc0023e6284 | 6 | #ifndef MBED_DIGITALIN_H |
| wyunreal | 3:5dc0023e6284 | 7 | #define MBED_DIGITALIN_H |
| wyunreal | 3:5dc0023e6284 | 8 | |
| wyunreal | 3:5dc0023e6284 | 9 | #include "platform.h" |
| wyunreal | 3:5dc0023e6284 | 10 | #include "PinNames.h" |
| wyunreal | 3:5dc0023e6284 | 11 | #include "PeripheralNames.h" |
| wyunreal | 3:5dc0023e6284 | 12 | #include "Base.h" |
| wyunreal | 3:5dc0023e6284 | 13 | |
| wyunreal | 3:5dc0023e6284 | 14 | namespace mbed { |
| wyunreal | 3:5dc0023e6284 | 15 | |
| wyunreal | 3:5dc0023e6284 | 16 | /* Class: DigitalIn |
| wyunreal | 3:5dc0023e6284 | 17 | * A digital input, used for reading the state of a pin |
| wyunreal | 3:5dc0023e6284 | 18 | * |
| wyunreal | 3:5dc0023e6284 | 19 | * Example: |
| wyunreal | 3:5dc0023e6284 | 20 | * > // Flash an LED while a DigitalIn is true |
| wyunreal | 3:5dc0023e6284 | 21 | * > |
| wyunreal | 3:5dc0023e6284 | 22 | * > #include "mbed.h" |
| wyunreal | 3:5dc0023e6284 | 23 | * > |
| wyunreal | 3:5dc0023e6284 | 24 | * > DigitalIn enable(p5); |
| wyunreal | 3:5dc0023e6284 | 25 | * > DigitalOut led(LED1); |
| wyunreal | 3:5dc0023e6284 | 26 | * > |
| wyunreal | 3:5dc0023e6284 | 27 | * > int main() { |
| wyunreal | 3:5dc0023e6284 | 28 | * > while(1) { |
| wyunreal | 3:5dc0023e6284 | 29 | * > if(enable) { |
| wyunreal | 3:5dc0023e6284 | 30 | * > led = !led; |
| wyunreal | 3:5dc0023e6284 | 31 | * > } |
| wyunreal | 3:5dc0023e6284 | 32 | * > wait(0.25); |
| wyunreal | 3:5dc0023e6284 | 33 | * > } |
| wyunreal | 3:5dc0023e6284 | 34 | * > } |
| wyunreal | 3:5dc0023e6284 | 35 | */ |
| wyunreal | 3:5dc0023e6284 | 36 | class DigitalIn : public Base { |
| wyunreal | 3:5dc0023e6284 | 37 | |
| wyunreal | 3:5dc0023e6284 | 38 | public: |
| wyunreal | 3:5dc0023e6284 | 39 | |
| wyunreal | 3:5dc0023e6284 | 40 | /* Constructor: DigitalIn |
| wyunreal | 3:5dc0023e6284 | 41 | * Create a DigitalIn connected to the specified pin |
| wyunreal | 3:5dc0023e6284 | 42 | * |
| wyunreal | 3:5dc0023e6284 | 43 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 44 | * pin - DigitalIn pin to connect to |
| wyunreal | 3:5dc0023e6284 | 45 | * name - (optional) A string to identify the object |
| wyunreal | 3:5dc0023e6284 | 46 | */ |
| wyunreal | 3:5dc0023e6284 | 47 | DigitalIn(PinName pin, const char *name = NULL); |
| wyunreal | 3:5dc0023e6284 | 48 | |
| wyunreal | 3:5dc0023e6284 | 49 | /* Function: read |
| wyunreal | 3:5dc0023e6284 | 50 | * Read the input, represented as 0 or 1 (int) |
| wyunreal | 3:5dc0023e6284 | 51 | * |
| wyunreal | 3:5dc0023e6284 | 52 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 53 | * returns - An integer representing the state of the input pin, |
| wyunreal | 3:5dc0023e6284 | 54 | * 0 for logical 0 and 1 for logical 1 |
| wyunreal | 3:5dc0023e6284 | 55 | */ |
| wyunreal | 3:5dc0023e6284 | 56 | int read() { |
| wyunreal | 3:5dc0023e6284 | 57 | return ((_gpio->FIOPIN & _mask) ? 1 : 0); |
| wyunreal | 3:5dc0023e6284 | 58 | } |
| wyunreal | 3:5dc0023e6284 | 59 | |
| wyunreal | 3:5dc0023e6284 | 60 | |
| wyunreal | 3:5dc0023e6284 | 61 | /* Function: mode |
| wyunreal | 3:5dc0023e6284 | 62 | * Set the input pin mode |
| wyunreal | 3:5dc0023e6284 | 63 | * |
| wyunreal | 3:5dc0023e6284 | 64 | * Variables: |
| wyunreal | 3:5dc0023e6284 | 65 | * mode - PullUp, PullDown, PullNone, OpenDrain |
| wyunreal | 3:5dc0023e6284 | 66 | */ |
| wyunreal | 3:5dc0023e6284 | 67 | void mode(PinMode pull); |
| wyunreal | 3:5dc0023e6284 | 68 | |
| wyunreal | 3:5dc0023e6284 | 69 | #ifdef MBED_OPERATORS |
| wyunreal | 3:5dc0023e6284 | 70 | /* Function: operator int() |
| wyunreal | 3:5dc0023e6284 | 71 | * An operator shorthand for <read()> |
| wyunreal | 3:5dc0023e6284 | 72 | */ |
| wyunreal | 3:5dc0023e6284 | 73 | operator int() { |
| wyunreal | 3:5dc0023e6284 | 74 | return read(); |
| wyunreal | 3:5dc0023e6284 | 75 | } |
| wyunreal | 3:5dc0023e6284 | 76 | |
| wyunreal | 3:5dc0023e6284 | 77 | #endif |
| wyunreal | 3:5dc0023e6284 | 78 | |
| wyunreal | 3:5dc0023e6284 | 79 | #ifdef MBED_RPC |
| wyunreal | 3:5dc0023e6284 | 80 | virtual const struct rpc_method *get_rpc_methods(); |
| wyunreal | 3:5dc0023e6284 | 81 | static struct rpc_class *get_rpc_class(); |
| wyunreal | 3:5dc0023e6284 | 82 | #endif |
| wyunreal | 3:5dc0023e6284 | 83 | |
| wyunreal | 3:5dc0023e6284 | 84 | protected: |
| wyunreal | 3:5dc0023e6284 | 85 | |
| wyunreal | 3:5dc0023e6284 | 86 | PinName _pin; |
| wyunreal | 3:5dc0023e6284 | 87 | LPC_GPIO_TypeDef *_gpio; |
| wyunreal | 3:5dc0023e6284 | 88 | uint32_t _mask; |
| wyunreal | 3:5dc0023e6284 | 89 | |
| wyunreal | 3:5dc0023e6284 | 90 | }; |
| wyunreal | 3:5dc0023e6284 | 91 | |
| wyunreal | 3:5dc0023e6284 | 92 | } // namespace mbed |
| wyunreal | 3:5dc0023e6284 | 93 | |
| wyunreal | 3:5dc0023e6284 | 94 | #endif |
| wyunreal | 3:5dc0023e6284 | 95 |
