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

Committer:
Jonathan Austin
Date:
Thu Apr 07 01:33:22 2016 +0100
Revision:
1:8aa5cdb4ab67
Child:
35:8ce23bc1af38
Synchronized with git rev 55cb9199

Who changed what in which revision?

UserRevisionLine numberNew 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
Jonathan Austin 1:8aa5cdb4ab67 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_TOUCH = 0x04,
Jonathan Austin 1:8aa5cdb4ab67 76 PIN_CAPABILITY_AD = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG,
Jonathan Austin 1:8aa5cdb4ab67 77 PIN_CAPABILITY_ALL = PIN_CAPABILITY_DIGITAL | PIN_CAPABILITY_ANALOG | PIN_CAPABILITY_TOUCH
Jonathan Austin 1:8aa5cdb4ab67 78
Jonathan Austin 1:8aa5cdb4ab67 79 };
Jonathan Austin 1:8aa5cdb4ab67 80
Jonathan Austin 1:8aa5cdb4ab67 81 /**
Jonathan Austin 1:8aa5cdb4ab67 82 * Class definition for MicroBitPin.
Jonathan Austin 1:8aa5cdb4ab67 83 *
Jonathan Austin 1:8aa5cdb4ab67 84 * Commonly represents an I/O pin on the edge connector.
Jonathan Austin 1:8aa5cdb4ab67 85 */
Jonathan Austin 1:8aa5cdb4ab67 86 class MicroBitPin : public MicroBitComponent
Jonathan Austin 1:8aa5cdb4ab67 87 {
Jonathan Austin 1:8aa5cdb4ab67 88 // The mbed object looking after this pin at any point in time (untyped due to dynamic behaviour).
Jonathan Austin 1:8aa5cdb4ab67 89 void *pin;
Jonathan Austin 1:8aa5cdb4ab67 90
Jonathan Austin 1:8aa5cdb4ab67 91 PinCapability capability;
Jonathan Austin 1:8aa5cdb4ab67 92
Jonathan Austin 1:8aa5cdb4ab67 93 /**
Jonathan Austin 1:8aa5cdb4ab67 94 * Disconnect any attached mBed IO from this pin.
Jonathan Austin 1:8aa5cdb4ab67 95 *
Jonathan Austin 1:8aa5cdb4ab67 96 * Used only when pin changes mode (i.e. Input/Output/Analog/Digital)
Jonathan Austin 1:8aa5cdb4ab67 97 */
Jonathan Austin 1:8aa5cdb4ab67 98 void disconnect();
Jonathan Austin 1:8aa5cdb4ab67 99
Jonathan Austin 1:8aa5cdb4ab67 100 /**
Jonathan Austin 1:8aa5cdb4ab67 101 * Performs a check to ensure that the current Pin is in control of a
Jonathan Austin 1:8aa5cdb4ab67 102 * DynamicPwm instance, and if it's not, allocates a new DynamicPwm instance.
Jonathan Austin 1:8aa5cdb4ab67 103 */
Jonathan Austin 1:8aa5cdb4ab67 104 int obtainAnalogChannel();
Jonathan Austin 1:8aa5cdb4ab67 105
Jonathan Austin 1:8aa5cdb4ab67 106 public:
Jonathan Austin 1:8aa5cdb4ab67 107
Jonathan Austin 1:8aa5cdb4ab67 108 // mbed PinName of this pin.
Jonathan Austin 1:8aa5cdb4ab67 109 PinName name;
Jonathan Austin 1:8aa5cdb4ab67 110
Jonathan Austin 1:8aa5cdb4ab67 111 /**
Jonathan Austin 1:8aa5cdb4ab67 112 * Constructor.
Jonathan Austin 1:8aa5cdb4ab67 113 * Create a MicroBitPin instance, generally used to represent a pin on the edge connector.
Jonathan Austin 1:8aa5cdb4ab67 114 *
Jonathan Austin 1:8aa5cdb4ab67 115 * @param id the unique EventModel id of this component.
Jonathan Austin 1:8aa5cdb4ab67 116 *
Jonathan Austin 1:8aa5cdb4ab67 117 * @param name the mbed PinName for this MicroBitPin instance.
Jonathan Austin 1:8aa5cdb4ab67 118 *
Jonathan Austin 1:8aa5cdb4ab67 119 * @param capability the capabilities this MicroBitPin instance should have.
Jonathan Austin 1:8aa5cdb4ab67 120 * (PIN_CAPABILITY_DIGITAL, PIN_CAPABILITY_ANALOG, PIN_CAPABILITY_TOUCH, PIN_CAPABILITY_AD, PIN_CAPABILITY_ALL)
Jonathan Austin 1:8aa5cdb4ab67 121 *
Jonathan Austin 1:8aa5cdb4ab67 122 * @code
Jonathan Austin 1:8aa5cdb4ab67 123 * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL);
Jonathan Austin 1:8aa5cdb4ab67 124 * @endcode
Jonathan Austin 1:8aa5cdb4ab67 125 */
Jonathan Austin 1:8aa5cdb4ab67 126 MicroBitPin(int id, PinName name, PinCapability capability);
Jonathan Austin 1:8aa5cdb4ab67 127
Jonathan Austin 1:8aa5cdb4ab67 128 /**
Jonathan Austin 1:8aa5cdb4ab67 129 * Configures this IO pin as a digital output (if necessary) and sets the pin to 'value'.
Jonathan Austin 1:8aa5cdb4ab67 130 *
Jonathan Austin 1:8aa5cdb4ab67 131 * @param value 0 (LO) or 1 (HI)
Jonathan Austin 1:8aa5cdb4ab67 132 *
Jonathan Austin 1:8aa5cdb4ab67 133 * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
Jonathan Austin 1:8aa5cdb4ab67 134 * if the given pin does not have digital capability.
Jonathan Austin 1:8aa5cdb4ab67 135 *
Jonathan Austin 1:8aa5cdb4ab67 136 * @code
Jonathan Austin 1:8aa5cdb4ab67 137 * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
Jonathan Austin 1:8aa5cdb4ab67 138 * P0.setDigitalValue(1); // P0 is now HI
Jonathan Austin 1:8aa5cdb4ab67 139 * @endcode
Jonathan Austin 1:8aa5cdb4ab67 140 */
Jonathan Austin 1:8aa5cdb4ab67 141 int setDigitalValue(int value);
Jonathan Austin 1:8aa5cdb4ab67 142
Jonathan Austin 1:8aa5cdb4ab67 143 /**
Jonathan Austin 1:8aa5cdb4ab67 144 * Configures this IO pin as a digital input (if necessary) and tests its current value.
Jonathan Austin 1:8aa5cdb4ab67 145 *
Jonathan Austin 1:8aa5cdb4ab67 146 * @return 1 if this input is high, 0 if input is LO, or MICROBIT_NOT_SUPPORTED
Jonathan Austin 1:8aa5cdb4ab67 147 * if the given pin does not have analog capability.
Jonathan Austin 1:8aa5cdb4ab67 148 *
Jonathan Austin 1:8aa5cdb4ab67 149 * @code
Jonathan Austin 1:8aa5cdb4ab67 150 * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
Jonathan Austin 1:8aa5cdb4ab67 151 * P0.getDigitalValue(); // P0 is either 0 or 1;
Jonathan Austin 1:8aa5cdb4ab67 152 * @endcode
Jonathan Austin 1:8aa5cdb4ab67 153 */
Jonathan Austin 1:8aa5cdb4ab67 154 int getDigitalValue();
Jonathan Austin 1:8aa5cdb4ab67 155
Jonathan Austin 1:8aa5cdb4ab67 156 /**
Jonathan Austin 1:8aa5cdb4ab67 157 * Configures this IO pin as an analog/pwm output, and change the output value to the given level.
Jonathan Austin 1:8aa5cdb4ab67 158 *
Jonathan Austin 1:8aa5cdb4ab67 159 * @param value the level to set on the output pin, in the range 0 - 1024
Jonathan Austin 1:8aa5cdb4ab67 160 *
Jonathan Austin 1:8aa5cdb4ab67 161 * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
Jonathan Austin 1:8aa5cdb4ab67 162 * if the given pin does not have analog capability.
Jonathan Austin 1:8aa5cdb4ab67 163 */
Jonathan Austin 1:8aa5cdb4ab67 164 int setAnalogValue(int value);
Jonathan Austin 1:8aa5cdb4ab67 165
Jonathan Austin 1:8aa5cdb4ab67 166 /**
Jonathan Austin 1:8aa5cdb4ab67 167 * Configures this IO pin as an analog/pwm output (if necessary) and configures the period to be 20ms,
Jonathan Austin 1:8aa5cdb4ab67 168 * with a duty cycle between 500 us and 2500 us.
Jonathan Austin 1:8aa5cdb4ab67 169 *
Jonathan Austin 1:8aa5cdb4ab67 170 * 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 171 *
Jonathan Austin 1:8aa5cdb4ab67 172 * This range can be modified to fine tune, and also tolerate different servos.
Jonathan Austin 1:8aa5cdb4ab67 173 *
Jonathan Austin 1:8aa5cdb4ab67 174 * @param value the level to set on the output pin, in the range 0 - 180.
Jonathan Austin 1:8aa5cdb4ab67 175 *
Jonathan Austin 1:8aa5cdb4ab67 176 * @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 177 *
Jonathan Austin 1:8aa5cdb4ab67 178 * @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 179 *
Jonathan Austin 1:8aa5cdb4ab67 180 * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
Jonathan Austin 1:8aa5cdb4ab67 181 * if the given pin does not have analog capability.
Jonathan Austin 1:8aa5cdb4ab67 182 */
Jonathan Austin 1:8aa5cdb4ab67 183 int setServoValue(int value, int range = MICROBIT_PIN_DEFAULT_SERVO_RANGE, int center = MICROBIT_PIN_DEFAULT_SERVO_CENTER);
Jonathan Austin 1:8aa5cdb4ab67 184
Jonathan Austin 1:8aa5cdb4ab67 185 /**
Jonathan Austin 1:8aa5cdb4ab67 186 * Configures this IO pin as an analogue input (if necessary), and samples the Pin for its analog value.
Jonathan Austin 1:8aa5cdb4ab67 187 *
Jonathan Austin 1:8aa5cdb4ab67 188 * @return the current analogue level on the pin, in the range 0 - 1024, or
Jonathan Austin 1:8aa5cdb4ab67 189 * MICROBIT_NOT_SUPPORTED if the given pin does not have analog capability.
Jonathan Austin 1:8aa5cdb4ab67 190 *
Jonathan Austin 1:8aa5cdb4ab67 191 * @code
Jonathan Austin 1:8aa5cdb4ab67 192 * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_BOTH);
Jonathan Austin 1:8aa5cdb4ab67 193 * P0.getAnalogValue(); // P0 is a value in the range of 0 - 1024
Jonathan Austin 1:8aa5cdb4ab67 194 * @endcode
Jonathan Austin 1:8aa5cdb4ab67 195 */
Jonathan Austin 1:8aa5cdb4ab67 196 int getAnalogValue();
Jonathan Austin 1:8aa5cdb4ab67 197
Jonathan Austin 1:8aa5cdb4ab67 198 /**
Jonathan Austin 1:8aa5cdb4ab67 199 * Determines if this IO pin is currently configured as an input.
Jonathan Austin 1:8aa5cdb4ab67 200 *
Jonathan Austin 1:8aa5cdb4ab67 201 * @return 1 if pin is an analog or digital input, 0 otherwise.
Jonathan Austin 1:8aa5cdb4ab67 202 */
Jonathan Austin 1:8aa5cdb4ab67 203 int isInput();
Jonathan Austin 1:8aa5cdb4ab67 204
Jonathan Austin 1:8aa5cdb4ab67 205 /**
Jonathan Austin 1:8aa5cdb4ab67 206 * Determines if this IO pin is currently configured as an output.
Jonathan Austin 1:8aa5cdb4ab67 207 *
Jonathan Austin 1:8aa5cdb4ab67 208 * @return 1 if pin is an analog or digital output, 0 otherwise.
Jonathan Austin 1:8aa5cdb4ab67 209 */
Jonathan Austin 1:8aa5cdb4ab67 210 int isOutput();
Jonathan Austin 1:8aa5cdb4ab67 211
Jonathan Austin 1:8aa5cdb4ab67 212 /**
Jonathan Austin 1:8aa5cdb4ab67 213 * Determines if this IO pin is currently configured for digital use.
Jonathan Austin 1:8aa5cdb4ab67 214 *
Jonathan Austin 1:8aa5cdb4ab67 215 * @return 1 if pin is digital, 0 otherwise.
Jonathan Austin 1:8aa5cdb4ab67 216 */
Jonathan Austin 1:8aa5cdb4ab67 217 int isDigital();
Jonathan Austin 1:8aa5cdb4ab67 218
Jonathan Austin 1:8aa5cdb4ab67 219 /**
Jonathan Austin 1:8aa5cdb4ab67 220 * Determines if this IO pin is currently configured for analog use.
Jonathan Austin 1:8aa5cdb4ab67 221 *
Jonathan Austin 1:8aa5cdb4ab67 222 * @return 1 if pin is analog, 0 otherwise.
Jonathan Austin 1:8aa5cdb4ab67 223 */
Jonathan Austin 1:8aa5cdb4ab67 224 int isAnalog();
Jonathan Austin 1:8aa5cdb4ab67 225
Jonathan Austin 1:8aa5cdb4ab67 226 /**
Jonathan Austin 1:8aa5cdb4ab67 227 * Configures this IO pin as a "makey makey" style touch sensor (if necessary)
Jonathan Austin 1:8aa5cdb4ab67 228 * and tests its current debounced state.
Jonathan Austin 1:8aa5cdb4ab67 229 *
Jonathan Austin 1:8aa5cdb4ab67 230 * Users can also subscribe to MicroBitButton events generated from this pin.
Jonathan Austin 1:8aa5cdb4ab67 231 *
Jonathan Austin 1:8aa5cdb4ab67 232 * @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 233 *
Jonathan Austin 1:8aa5cdb4ab67 234 * @code
Jonathan Austin 1:8aa5cdb4ab67 235 * MicroBitMessageBus bus;
Jonathan Austin 1:8aa5cdb4ab67 236 *
Jonathan Austin 1:8aa5cdb4ab67 237 * MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL);
Jonathan Austin 1:8aa5cdb4ab67 238 * if(P0.isTouched())
Jonathan Austin 1:8aa5cdb4ab67 239 * {
Jonathan Austin 1:8aa5cdb4ab67 240 * //do something!
Jonathan Austin 1:8aa5cdb4ab67 241 * }
Jonathan Austin 1:8aa5cdb4ab67 242 *
Jonathan Austin 1:8aa5cdb4ab67 243 * // subscribe to events generated by this pin!
Jonathan Austin 1:8aa5cdb4ab67 244 * bus.listen(MICROBIT_ID_IO_P0, MICROBIT_BUTTON_EVT_CLICK, someFunction);
Jonathan Austin 1:8aa5cdb4ab67 245 * @endcode
Jonathan Austin 1:8aa5cdb4ab67 246 */
Jonathan Austin 1:8aa5cdb4ab67 247 int isTouched();
Jonathan Austin 1:8aa5cdb4ab67 248
Jonathan Austin 1:8aa5cdb4ab67 249 /**
Jonathan Austin 1:8aa5cdb4ab67 250 * Configures this IO pin as an analog/pwm output if it isn't already, configures the period to be 20ms,
Jonathan Austin 1:8aa5cdb4ab67 251 * and sets the pulse width, based on the value it is given.
Jonathan Austin 1:8aa5cdb4ab67 252 *
Jonathan Austin 1:8aa5cdb4ab67 253 * @param pulseWidth the desired pulse width in microseconds.
Jonathan Austin 1:8aa5cdb4ab67 254 *
Jonathan Austin 1:8aa5cdb4ab67 255 * @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER if value is out of range, or MICROBIT_NOT_SUPPORTED
Jonathan Austin 1:8aa5cdb4ab67 256 * if the given pin does not have analog capability.
Jonathan Austin 1:8aa5cdb4ab67 257 */
Jonathan Austin 1:8aa5cdb4ab67 258 int setServoPulseUs(int pulseWidth);
Jonathan Austin 1:8aa5cdb4ab67 259
Jonathan Austin 1:8aa5cdb4ab67 260 /**
Jonathan Austin 1:8aa5cdb4ab67 261 * Configures the PWM period of the analog output to the given value.
Jonathan Austin 1:8aa5cdb4ab67 262 *
Jonathan Austin 1:8aa5cdb4ab67 263 * @param period The new period for the analog output in milliseconds.
Jonathan Austin 1:8aa5cdb4ab67 264 *
Jonathan Austin 1:8aa5cdb4ab67 265 * @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the
Jonathan Austin 1:8aa5cdb4ab67 266 * given pin is not configured as an analog output.
Jonathan Austin 1:8aa5cdb4ab67 267 */
Jonathan Austin 1:8aa5cdb4ab67 268 int setAnalogPeriod(int period);
Jonathan Austin 1:8aa5cdb4ab67 269
Jonathan Austin 1:8aa5cdb4ab67 270 /**
Jonathan Austin 1:8aa5cdb4ab67 271 * Configures the PWM period of the analog output to the given value.
Jonathan Austin 1:8aa5cdb4ab67 272 *
Jonathan Austin 1:8aa5cdb4ab67 273 * @param period The new period for the analog output in microseconds.
Jonathan Austin 1:8aa5cdb4ab67 274 *
Jonathan Austin 1:8aa5cdb4ab67 275 * @return MICROBIT_OK on success, or MICROBIT_NOT_SUPPORTED if the
Jonathan Austin 1:8aa5cdb4ab67 276 * given pin is not configured as an analog output.
Jonathan Austin 1:8aa5cdb4ab67 277 */
Jonathan Austin 1:8aa5cdb4ab67 278 int setAnalogPeriodUs(int period);
Jonathan Austin 1:8aa5cdb4ab67 279
Jonathan Austin 1:8aa5cdb4ab67 280 /**
Jonathan Austin 1:8aa5cdb4ab67 281 * Obtains the PWM period of the analog output in microseconds.
Jonathan Austin 1:8aa5cdb4ab67 282 *
Jonathan Austin 1:8aa5cdb4ab67 283 * @return the period on success, or MICROBIT_NOT_SUPPORTED if the
Jonathan Austin 1:8aa5cdb4ab67 284 * given pin is not configured as an analog output.
Jonathan Austin 1:8aa5cdb4ab67 285 */
Jonathan Austin 1:8aa5cdb4ab67 286 int getAnalogPeriodUs();
Jonathan Austin 1:8aa5cdb4ab67 287
Jonathan Austin 1:8aa5cdb4ab67 288 /**
Jonathan Austin 1:8aa5cdb4ab67 289 * Obtains the PWM period of the analog output in milliseconds.
Jonathan Austin 1:8aa5cdb4ab67 290 *
Jonathan Austin 1:8aa5cdb4ab67 291 * @return the period on success, or MICROBIT_NOT_SUPPORTED if the
Jonathan Austin 1:8aa5cdb4ab67 292 * given pin is not configured as an analog output.
Jonathan Austin 1:8aa5cdb4ab67 293 */
Jonathan Austin 1:8aa5cdb4ab67 294 int getAnalogPeriod();
Jonathan Austin 1:8aa5cdb4ab67 295 };
Jonathan Austin 1:8aa5cdb4ab67 296
Jonathan Austin 1:8aa5cdb4ab67 297 #endif