mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal
Dependencies: BLE_API nRF51822 mbed-dev-bin
Dependents: microbit Microbit IoTChallenge1 microbit ... more
inc/drivers/MicroBitPin.h@45:23b71960fe6c, 2016-07-13 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:24 2016 +0100
- Revision:
- 45:23b71960fe6c
- Parent:
- 37:b624ae5e94a5
- Child:
- 49:88f03f3feff1
Synchronized with git rev e9353806
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
1:8aa5cdb4ab67 | 1 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 2 | The MIT License (MIT) |
Jonathan Austin |
1:8aa5cdb4ab67 | 3 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
Jonathan Austin |
1:8aa5cdb4ab67 | 6 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
Jonathan Austin |
1:8aa5cdb4ab67 | 8 | copy of this software and associated documentation files (the "Software"), |
Jonathan Austin |
1:8aa5cdb4ab67 | 9 | to deal in the Software without restriction, including without limitation |
Jonathan Austin |
1:8aa5cdb4ab67 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Jonathan Austin |
1:8aa5cdb4ab67 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
Jonathan Austin |
1:8aa5cdb4ab67 | 12 | Software is furnished to do so, subject to the following conditions: |
Jonathan Austin |
1:8aa5cdb4ab67 | 13 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 14 | The above copyright notice and this permission notice shall be included in |
Jonathan Austin |
1:8aa5cdb4ab67 | 15 | all copies or substantial portions of the Software. |
Jonathan Austin |
1:8aa5cdb4ab67 | 16 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Jonathan Austin |
1:8aa5cdb4ab67 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jonathan Austin |
1:8aa5cdb4ab67 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Jonathan Austin |
1:8aa5cdb4ab67 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
Jonathan Austin |
1:8aa5cdb4ab67 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 23 | DEALINGS IN THE SOFTWARE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 24 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 25 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 26 | #ifndef MICROBIT_PIN_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | #define MICROBIT_PIN_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | #include "mbed.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | #include "MicroBitComponent.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | // Status Field flags... |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | #define IO_STATUS_DIGITAL_IN 0x01 // Pin is configured as a digital input, with no pull up. |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | #define IO_STATUS_DIGITAL_OUT 0x02 // Pin is configured as a digital output |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | #define IO_STATUS_ANALOG_IN 0x04 // Pin is Analog in |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | #define IO_STATUS_ANALOG_OUT 0x08 // Pin is Analog out |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | #define IO_STATUS_TOUCH_IN 0x10 // Pin is a makey-makey style touch sensor |
LancasterUniversity | 37:b624ae5e94a5 | 38 | #define IO_STATUS_EVENTBUS_ENABLED 0x80 // Pin is will generate events on change |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | //#defines for each edge connector pin |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | #define MICROBIT_PIN_P0 P0_3 //P0 is the left most pad (ANALOG/DIGITAL) used to be P0_3 on green board |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | #define MICROBIT_PIN_P1 P0_2 //P1 is the middle pad (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | #define MICROBIT_PIN_P2 P0_1 //P2 is the right most pad (ANALOG/DIGITAL) used to be P0_1 on green board |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | #define MICROBIT_PIN_P3 P0_4 //COL1 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | #define MICROBIT_PIN_P4 P0_5 //COL2 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | #define MICROBIT_PIN_P5 P0_17 //BTN_A |
Jonathan Austin |
1:8aa5cdb4ab67 | 47 | #define MICROBIT_PIN_P6 P0_12 //COL9 |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | #define MICROBIT_PIN_P7 P0_11 //COL8 |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | #define MICROBIT_PIN_P8 P0_18 //PIN 18 |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | #define MICROBIT_PIN_P9 P0_10 //COL7 |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | #define MICROBIT_PIN_P10 P0_6 //COL3 (ANALOG/DIGITAL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | #define MICROBIT_PIN_P11 P0_26 //BTN_B |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | #define MICROBIT_PIN_P12 P0_20 //PIN 20 |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | #define MICROBIT_PIN_P13 P0_23 //SCK |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | #define MICROBIT_PIN_P14 P0_22 //MISO |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | #define MICROBIT_PIN_P15 P0_21 //MOSI |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | #define MICROBIT_PIN_P16 P0_16 //PIN 16 |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | #define MICROBIT_PIN_P19 P0_0 //SCL |
Jonathan Austin |
1:8aa5cdb4ab67 | 59 | #define MICROBIT_PIN_P20 P0_30 //SDA |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | #define MICROBIT_PIN_MAX_OUTPUT 1023 |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | #define MICROBIT_PIN_MAX_SERVO_RANGE 180 |
Jonathan Austin |
1:8aa5cdb4ab67 | 64 | #define MICROBIT_PIN_DEFAULT_SERVO_RANGE 2000 |
Jonathan Austin |
1:8aa5cdb4ab67 | 65 | #define MICROBIT_PIN_DEFAULT_SERVO_CENTER 1500 |
Jonathan Austin |
1:8aa5cdb4ab67 | 66 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 67 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 69 | * Pin capabilities enum. |
Jonathan Austin |
1:8aa5cdb4ab67 | 70 | * Used to determine the capabilities of each Pin as some can only be digital, or can be both digital and analogue. |
Jonathan Austin |
1:8aa5cdb4ab67 | 71 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 72 | enum PinCapability{ |
Jonathan Austin |
1:8aa5cdb4ab67 | 73 | PIN_CAPABILITY_DIGITAL = 0x01, |
Jonathan Austin |
1:8aa5cdb4ab67 | 74 | PIN_CAPABILITY_ANALOG = 0x02, |
Jonathan Austin |
1:8aa5cdb4ab67 | 75 | PIN_CAPABILITY_AD = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG, |
LancasterUniversity | 45:23b71960fe6c | 76 | PIN_CAPABILITY_ALL = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | * Class definition for MicroBitPin. |
Jonathan Austin |
1:8aa5cdb4ab67 | 81 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | * Commonly represents an I/O pin on the edge connector. |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 84 | class MicroBitPin : public MicroBitComponent |
Jonathan Austin |
1:8aa5cdb4ab67 | 85 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 86 | // The mbed object looking after this pin at any point in time (untyped due to dynamic behaviour). |
Jonathan Austin |
1:8aa5cdb4ab67 | 87 | void *pin; |
Jonathan Austin |
1:8aa5cdb4ab67 | 88 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 89 | PinCapability capability; |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 91 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 92 | * Disconnect any attached mBed IO from this pin. |
Jonathan Austin |
1:8aa5cdb4ab67 | 93 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 94 | * Used only when pin changes mode (i.e. Input/Output/Analog/Digital) |
Jonathan Austin |
1:8aa5cdb4ab67 | 95 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 96 | void disconnect(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 98 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 99 | * Performs a check to ensure that the current Pin is in control of a |
Jonathan Austin |
1:8aa5cdb4ab67 | 100 | * DynamicPwm instance, and if it's not, allocates a new DynamicPwm instance. |
Jonathan Austin |
1:8aa5cdb4ab67 | 101 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 102 | int obtainAnalogChannel(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 103 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 104 | public: |
Jonathan Austin |
1:8aa5cdb4ab67 | 105 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 106 | // mbed PinName of this pin. |
Jonathan Austin |
1:8aa5cdb4ab67 | 107 | PinName name; |
Jonathan Austin |
1:8aa5cdb4ab67 | 108 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 109 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 110 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 111 | * Create a MicroBitPin instance, generally used to represent a pin on the edge connector. |
Jonathan Austin |
1:8aa5cdb4ab67 | 112 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 113 | * @param id the unique EventModel id of this component. |
Jonathan Austin |
1:8aa5cdb4ab67 | 114 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 115 | * @param name the mbed PinName for this MicroBitPin instance. |
Jonathan Austin |
1:8aa5cdb4ab67 | 116 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 117 | * @param capability the capabilities this MicroBitPin instance should have. |
LancasterUniversity | 45:23b71960fe6c | 118 | * (PIN_CAPABILITY_DIGITAL, PIN_CAPABILITY_ANALOG, PIN_CAPABILITY_AD, PIN_CAPABILITY_ALL) |
Jonathan Austin |
1:8aa5cdb4ab67 | 119 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 120 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 121 | * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL); |
Jonathan Austin |
1:8aa5cdb4ab67 | 122 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 123 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 124 | MicroBitPin(int id, PinName name, PinCapability capability); |
Jonathan Austin |
1:8aa5cdb4ab67 | 125 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 126 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 127 | * Configures this IO pin as a digital output (if necessary) and sets the pin to 'value'. |
Jonathan Austin |
1:8aa5cdb4ab67 | 128 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 129 | * @param value 0 (LO) or 1 (HI) |
Jonathan Austin |
1:8aa5cdb4ab67 | 130 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 131 | * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED |
Jonathan Austin |
1:8aa5cdb4ab67 | 132 | * if the given pin does not have digital capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 133 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 134 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 135 | * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); |
Jonathan Austin |
1:8aa5cdb4ab67 | 136 | * P0.setDigitalValue(1); // P0 is now HI |
Jonathan Austin |
1:8aa5cdb4ab67 | 137 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 138 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 139 | int setDigitalValue(int value); |
Jonathan Austin |
1:8aa5cdb4ab67 | 140 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 141 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 142 | * Configures this IO pin as a digital input (if necessary) and tests its current value. |
Jonathan Austin |
1:8aa5cdb4ab67 | 143 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 144 | * @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED |
LancasterUniversity | 37:b624ae5e94a5 | 145 | * if the given pin does not have analog capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 146 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 147 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 148 | * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); |
Jonathan Austin |
1:8aa5cdb4ab67 | 149 | * P0.getDigitalValue(); // P0 is either 0 or 1; |
Jonathan Austin |
1:8aa5cdb4ab67 | 150 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 151 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 152 | int getDigitalValue(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 153 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 154 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 155 | * Configures this IO pin as an analog/pwm output, and change the output value to the given level. |
Jonathan Austin |
1:8aa5cdb4ab67 | 156 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 157 | * @param value the level to set on the output pin, in the range 0 - 1024 |
Jonathan Austin |
1:8aa5cdb4ab67 | 158 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 159 | * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED |
Jonathan Austin |
1:8aa5cdb4ab67 | 160 | * if the given pin does not have analog capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 161 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 162 | int setAnalogValue(int value); |
Jonathan Austin |
1:8aa5cdb4ab67 | 163 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 164 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 165 | * Configures this IO pin as an analog/pwm output (if necessary) and configures the period to be 20ms, |
Jonathan Austin |
1:8aa5cdb4ab67 | 166 | * with a duty cycle between 500 us and 2500 us. |
Jonathan Austin |
1:8aa5cdb4ab67 | 167 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 168 | * A value of 180 sets the duty cycle to be 2500us, and a value of 0 sets the duty cycle to be 500us by default. |
Jonathan Austin |
1:8aa5cdb4ab67 | 169 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 170 | * This range can be modified to fine tune, and also tolerate different servos. |
Jonathan Austin |
1:8aa5cdb4ab67 | 171 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 172 | * @param value the level to set on the output pin, in the range 0 - 180. |
Jonathan Austin |
1:8aa5cdb4ab67 | 173 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 174 | * @param range which gives the span of possible values the i.e. the lower and upper bounds (center +/- range/2). Defaults to MICROBIT_PIN_DEFAULT_SERVO_RANGE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 175 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 176 | * @param center the center point from which to calculate the lower and upper bounds. Defaults to MICROBIT_PIN_DEFAULT_SERVO_CENTER |
Jonathan Austin |
1:8aa5cdb4ab67 | 177 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 178 | * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED |
Jonathan Austin |
1:8aa5cdb4ab67 | 179 | * if the given pin does not have analog capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 180 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 181 | int setServoValue(int value, int range = MICROBIT_PIN_DEFAULT_SERVO_RANGE, int center = MICROBIT_PIN_DEFAULT_SERVO_CENTER); |
Jonathan Austin |
1:8aa5cdb4ab67 | 182 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 183 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 184 | * Configures this IO pin as an analogue input (if necessary), and samples the Pin for its analog value. |
Jonathan Austin |
1:8aa5cdb4ab67 | 185 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 186 | * @return the current analogue level on the pin, in the range 0 - 1024, or |
Jonathan Austin |
1:8aa5cdb4ab67 | 187 | * MICROBIT_NOT_SUPPORTED if the given pin does not have analog capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 188 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 189 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 190 | * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH); |
Jonathan Austin |
1:8aa5cdb4ab67 | 191 | * P0.getAnalogValue(); // P0 is a value in the range of 0 - 1024 |
Jonathan Austin |
1:8aa5cdb4ab67 | 192 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 193 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 194 | int getAnalogValue(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 195 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 196 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 197 | * Determines if this IO pin is currently configured as an input. |
Jonathan Austin |
1:8aa5cdb4ab67 | 198 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 199 | * @return 1 if pin is an analog or digital input, 0 otherwise. |
Jonathan Austin |
1:8aa5cdb4ab67 | 200 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 201 | int isInput(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 202 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 203 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 204 | * Determines if this IO pin is currently configured as an output. |
Jonathan Austin |
1:8aa5cdb4ab67 | 205 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 206 | * @return 1 if pin is an analog or digital output, 0 otherwise. |
Jonathan Austin |
1:8aa5cdb4ab67 | 207 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 208 | int isOutput(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 209 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 210 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 211 | * Determines if this IO pin is currently configured for digital use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 212 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 213 | * @return 1 if pin is digital, 0 otherwise. |
Jonathan Austin |
1:8aa5cdb4ab67 | 214 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 215 | int isDigital(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 216 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 217 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 218 | * Determines if this IO pin is currently configured for analog use. |
Jonathan Austin |
1:8aa5cdb4ab67 | 219 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 220 | * @return 1 if pin is analog, 0 otherwise. |
Jonathan Austin |
1:8aa5cdb4ab67 | 221 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 222 | int isAnalog(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 223 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 224 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 225 | * Configures this IO pin as a "makey makey" style touch sensor (if necessary) |
Jonathan Austin |
1:8aa5cdb4ab67 | 226 | * and tests its current debounced state. |
Jonathan Austin |
1:8aa5cdb4ab67 | 227 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 228 | * Users can also subscribe to MicroBitButton events generated from this pin. |
Jonathan Austin |
1:8aa5cdb4ab67 | 229 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 230 | * @return 1 if pin is touched, 0 if not, or MICROBIT_NOT_SUPPORTED if this pin does not support touch capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 231 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 232 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 233 | * MicroBitMessageBus bus; |
Jonathan Austin |
1:8aa5cdb4ab67 | 234 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 235 | * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL); |
Jonathan Austin |
1:8aa5cdb4ab67 | 236 | * if(P0.isTouched()) |
Jonathan Austin |
1:8aa5cdb4ab67 | 237 | * { |
Jonathan Austin |
1:8aa5cdb4ab67 | 238 | * //do something! |
Jonathan Austin |
1:8aa5cdb4ab67 | 239 | * } |
Jonathan Austin |
1:8aa5cdb4ab67 | 240 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 241 | * // subscribe to events generated by this pin! |
Jonathan Austin |
1:8aa5cdb4ab67 | 242 | * bus.listen(MICROBIT_ID_IO_P0, MICROBIT_BUTTON_EVT_CLICK, someFunction); |
Jonathan Austin |
1:8aa5cdb4ab67 | 243 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 244 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 245 | int isTouched(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 246 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 247 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 248 | * Configures this IO pin as an analog/pwm output if it isn't already, configures the period to be 20ms, |
Jonathan Austin |
1:8aa5cdb4ab67 | 249 | * and sets the pulse width, based on the value it is given. |
Jonathan Austin |
1:8aa5cdb4ab67 | 250 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 251 | * @param pulseWidth the desired pulse width in microseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 252 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 253 | * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED |
Jonathan Austin |
1:8aa5cdb4ab67 | 254 | * if the given pin does not have analog capability. |
Jonathan Austin |
1:8aa5cdb4ab67 | 255 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 256 | int setServoPulseUs(int pulseWidth); |
Jonathan Austin |
1:8aa5cdb4ab67 | 257 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 258 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 259 | * Configures the PWM period of the analog output to the given value. |
Jonathan Austin |
1:8aa5cdb4ab67 | 260 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 261 | * @param period The new period for the analog output in milliseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 262 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 263 | * @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the |
Jonathan Austin |
1:8aa5cdb4ab67 | 264 | * given pin is not configured as an analog output. |
Jonathan Austin |
1:8aa5cdb4ab67 | 265 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 266 | int setAnalogPeriod(int period); |
Jonathan Austin |
1:8aa5cdb4ab67 | 267 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 268 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 269 | * Configures the PWM period of the analog output to the given value. |
Jonathan Austin |
1:8aa5cdb4ab67 | 270 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 271 | * @param period The new period for the analog output in microseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 272 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 273 | * @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the |
Jonathan Austin |
1:8aa5cdb4ab67 | 274 | * given pin is not configured as an analog output. |
Jonathan Austin |
1:8aa5cdb4ab67 | 275 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 276 | int setAnalogPeriodUs(int period); |
Jonathan Austin |
1:8aa5cdb4ab67 | 277 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 278 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 279 | * Obtains the PWM period of the analog output in microseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 280 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 281 | * @return the period on success, or MICROBIT_NOT_SUPPORTED if the |
Jonathan Austin |
1:8aa5cdb4ab67 | 282 | * given pin is not configured as an analog output. |
Jonathan Austin |
1:8aa5cdb4ab67 | 283 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 284 | int getAnalogPeriodUs(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 285 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 286 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 287 | * Obtains the PWM period of the analog output in milliseconds. |
Jonathan Austin |
1:8aa5cdb4ab67 | 288 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 289 | * @return the period on success, or MICROBIT_NOT_SUPPORTED if the |
Jonathan Austin |
1:8aa5cdb4ab67 | 290 | * given pin is not configured as an analog output. |
Jonathan Austin |
1:8aa5cdb4ab67 | 291 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 292 | int getAnalogPeriod(); |
Jonathan Austin |
1:8aa5cdb4ab67 | 293 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 294 | |
LancasterUniversity | 35:8ce23bc1af38 | 295 | #endif |