@ -3,36 +3,40 @@
# include "mbed.h"
# include "MicroBitComponent.h"
// Status Field flags...
# define IO_STATUS_DIGITAL_IN 0x01 // Pin is configured as a digital input, with no pull up.
# define IO_STATUS_DIGITAL_OUT 0x02 // Pin is configured as a digital output
# define IO_STATUS_ANALOG_IN 0x04 // Pin is Analog in
# define IO_STATUS_ANALOG_OUT 0x08 // Pin is Analog out
# define IO_STATUS_TOUCH_IN 0x10 // Pin is a makey-makey style touch sensor
# define IO_STATUS_EVENTBUS_ENABLED 0x80 // Pin is will generate events on change
// Status Field flags...
# define IO_STATUS_DIGITAL_IN 0x01 // Pin is configured as a digital input, with no pull up.
# define IO_STATUS_DIGITAL_OUT 0x02 // Pin is configured as a digital output
# define IO_STATUS_ANALOG_IN 0x04 // Pin is Analog in
# define IO_STATUS_ANALOG_OUT 0x08 // Pin is Analog out
# define IO_STATUS_TOUCH_IN 0x10 // Pin is a makey-makey style touch sensor
# define IO_STATUS_EVENTBUS_ENABLED 0x80 // Pin is will generate events on change
//#defines for each edge connector pin
# define MICROBIT_PIN_P0 P0_3 //P0 is the left most pad (ANALOG/DIGITAL) used to be P0_3 on green board
# define MICROBIT_PIN_P1 P0_2 //P1 is the middle pad (ANALOG/DIGITAL)
# define MICROBIT_PIN_P2 P0_1 //P2 is the right most pad (ANALOG/DIGITAL) used to be P0_1 on green board
# define MICROBIT_PIN_P3 P0_4 //COL1 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P4 P0_17 //BTN_A
# define MICROBIT_PIN_P5 P0_5 //COL2 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P6 P0_12 //COL9
# define MICROBIT_PIN_P7 P0_11 //COL8
# define MICROBIT_PIN_P8 P0_18 //PIN 18
# define MICROBIT_PIN_P9 P0_10 //COL7
# define MICROBIT_PIN_P10 P0_6 //COL3 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P11 P0_26 //BTN_B
# define MICROBIT_PIN_P12 P0_20 //PIN 20
# define MICROBIT_PIN_P13 P0_23 //SCK
# define MICROBIT_PIN_P14 P0_22 //MISO
# define MICROBIT_PIN_P15 P0_21 //MOSI
# define MICROBIT_PIN_P16 P0_16 //PIN 16
# define MICROBIT_PIN_P19 P0_0 //SCL
# define MICROBIT_PIN_P20 P0_30 //SDA
# define MICROBIT_PIN_MAX_OUTPUT 1023
# define MICROBIT_PIN_P0 P0_3 //P0 is the left most pad (ANALOG/DIGITAL) used to be P0_3 on green board
# define MICROBIT_PIN_P1 P0_2 //P1 is the middle pad (ANALOG/DIGITAL)
# define MICROBIT_PIN_P2 P0_1 //P2 is the right most pad (ANALOG/DIGITAL) used to be P0_1 on green board
# define MICROBIT_PIN_P3 P0_4 //COL1 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P4 P0_17 //BTN_A
# define MICROBIT_PIN_P5 P0_5 //COL2 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P6 P0_12 //COL9
# define MICROBIT_PIN_P7 P0_11 //COL8
# define MICROBIT_PIN_P8 P0_18 //PIN 18
# define MICROBIT_PIN_P9 P0_10 //COL7
# define MICROBIT_PIN_P10 P0_6 //COL3 (ANALOG/DIGITAL)
# define MICROBIT_PIN_P11 P0_26 //BTN_B
# define MICROBIT_PIN_P12 P0_20 //PIN 20
# define MICROBIT_PIN_P13 P0_23 //SCK
# define MICROBIT_PIN_P14 P0_22 //MISO
# define MICROBIT_PIN_P15 P0_21 //MOSI
# define MICROBIT_PIN_P16 P0_16 //PIN 16
# define MICROBIT_PIN_P19 P0_0 //SCL
# define MICROBIT_PIN_P20 P0_30 //SDA
# define MICROBIT_PIN_MAX_OUTPUT 1023
# define MICROBIT_PIN_MAX_SERVO_RANGE 180
# define MICROBIT_PIN_DEFAULT_SERVO_RANGE 1000
# define MICROBIT_PIN_DEFAULT_SERVO_CENTER MICROBIT_PIN_DEFAULT_SERVO_RANGE + MICROBIT_PIN_DEFAULT_SERVO_RANGE / 2
/**
@ -69,6 +73,12 @@ class MicroBitPin : public MicroBitComponent
*/
void disconnect ( ) ;
/**
* Performs a check to ensure that the current Pin is in control of a
* DynamicPwm instance , and if it ' s not , allocates a new DynamicPwm instance .
*/
int obtainAnalogChannel ( ) ;
public :
PinName name ; // mBed pin name of this pin.
@ -120,6 +130,21 @@ class MicroBitPin : public MicroBitComponent
*/
int setAnalogValue ( int value ) ;
/**
* Configures this IO pin as an analog / pwm output if it isn ' t already , configures the period to be 20 ms ,
* and sets the duty cycle between 0.05 and 0.1 ( i . e . 5 % or 10 % ) based on the value given to this method .
*
* A value of 180 sets the duty cycle to be 10 % , and a value of 0 sets the duty cycle to be 5 % by default .
*
* This range can be modified to fine tune , and also tolerate different servos .
*
* @ param value the level to set on the output pin , in the range 0 - 180
* @ param range which gives the span of possible values the i . e . lower and upper bounds center ± range / 2 ( Defaults to : MICROBIT_PIN_DEFAULT_SERVO_RANGE )
* @ param center the center point from which to calculate the lower and upper bounds ( Defaults to : MICROBIT_PIN_DEFAULT_SERVO_CENTER )
* @ return MICROBIT_OK on success , MICROBIT_INVALID_PARAMETER if value is out of range , or MICROBIT_NOT_SUPPORTED
* if the given pin does not have analog capability .
*/
int setServoValue ( int value , int range = MICROBIT_PIN_DEFAULT_SERVO_RANGE , int center = MICROBIT_PIN_DEFAULT_SERVO_CENTER ) ;
/**
* Configures this IO pin as an analogue input ( if necessary and possible ) .
@ -172,6 +197,16 @@ class MicroBitPin : public MicroBitComponent
*/
int isTouched ( ) ;
/**
* Configures this IO pin as an analog / pwm output if it isn ' t already , configures the period to be 20 ms ,
* and sets the pulse width , based on the value it is given
*
* @ param pulseWidth the desired pulse width in microseconds .
* @ return MICROBIT_OK on success , MICROBIT_INVALID_PARAMETER if value is out of range , or MICROBIT_NOT_SUPPORTED
* if the given pin does not have analog capability .
*/
int setServoPulseUs ( int pulseWidth ) ;
/**
* Configures the PWM period of the analog output to the given value .
*