pxt-calliope/libs/microbit/pins.ts

156 lines
5.9 KiB
TypeScript
Raw Normal View History

enum DigitalPin {
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP0
2016-03-10 23:01:04 +01:00
P0,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP1
2016-03-10 23:01:04 +01:00
P1,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP2
2016-03-10 23:01:04 +01:00
P2,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP3
2016-03-10 23:01:04 +01:00
P3,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP4
2016-03-10 23:01:04 +01:00
P4,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP5
2016-03-10 23:01:04 +01:00
P5,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP6
2016-03-10 23:01:04 +01:00
P6,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP7
2016-03-10 23:01:04 +01:00
P7,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP8
2016-03-10 23:01:04 +01:00
P8,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP9
2016-03-10 23:01:04 +01:00
P9,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP10
2016-03-10 23:01:04 +01:00
P10,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP11
2016-03-10 23:01:04 +01:00
P11,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP12
2016-03-10 23:01:04 +01:00
P12,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP13
2016-03-10 23:01:04 +01:00
P13,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP14
2016-03-10 23:01:04 +01:00
P14,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP15
2016-03-10 23:01:04 +01:00
P15,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP16
2016-03-10 23:01:04 +01:00
P16,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP19
2016-03-10 23:01:04 +01:00
P19,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP20
2016-03-10 23:01:04 +01:00
P20,
}
enum AnalogPin {
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP0
2016-03-10 23:01:04 +01:00
P0,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP1
2016-03-10 23:01:04 +01:00
P1,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP2
2016-03-10 23:01:04 +01:00
P2,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP3
2016-03-10 23:01:04 +01:00
P3,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP4
2016-03-10 23:01:04 +01:00
P4,
2016-04-02 03:29:39 +02:00
//% enumval=micro_bit::ioP10
2016-03-10 23:01:04 +01:00
P10,
}
//% color=351 weight=30
namespace pins {
/**
* Read the specified pin or connector as either 0 or 1
* @param name pin to read from
*/
2016-03-22 06:13:39 +01:00
//% help=pins/digital-read-pin weight=30 shim=micro_bit::digitalReadPin
2016-03-10 23:01:04 +01:00
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
export function digitalReadPin(name: DigitalPin): number {
2016-03-10 23:01:04 +01:00
return 0;
}
/**
* Set a pin or connector value to either 0 or 1.
* @param name pin to write to
* @param value value to set on the pin, eg: 1,0
*/
2016-03-22 06:13:39 +01:00
//% help=pins/digital-write-pin weight=29 shim=micro_bit::digitalWritePin
2016-03-10 23:01:04 +01:00
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
export function digitalWritePin(name: DigitalPin, value: number): void { }
2016-03-10 23:01:04 +01:00
/**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to
*/
2016-03-22 06:13:39 +01:00
//% help=pins/analog-read-pin weight=25 shim=micro_bit::analogReadPin
2016-03-10 23:01:04 +01:00
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
export function analogReadPin(name: AnalogPin): number {
2016-03-10 23:01:04 +01:00
return 0;
}
/**
* Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/
2016-03-22 06:13:39 +01:00
//% help=pins/analog-write-pin weight=24 shim=micro_bit::analogWritePin
2016-03-10 23:01:04 +01:00
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
export function analogWritePin(name: AnalogPin, value: number): void { }
2016-03-10 23:01:04 +01:00
/**
* Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.
* If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.
* @param pin analog pin to set period to
* @param micros period in micro seconds. eg:20000
*/
2016-03-22 06:13:39 +01:00
//% shim=micro_bit::setAnalogPeriodUs help=pins/analog-set-period weight=23
2016-03-10 23:01:04 +01:00
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
export function analogSetPeriod(pin: AnalogPin, micros: number): void { }
2016-03-10 23:01:04 +01:00
/**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to
* @param value angle or rotation speed, eg:180,90,0
*/
2016-03-22 06:13:39 +01:00
//% help=pins/servo-write-pin weight=20 shim=micro_bit::servoWritePin
2016-03-10 23:01:04 +01:00
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
export function servoWritePin(name: AnalogPin, value: number): void { }
2016-03-10 23:01:04 +01:00
/**
* Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.
* @param pin pin name
* @param micros pulse duration in micro seconds, eg:1500
*/
2016-03-22 06:13:39 +01:00
//% shim=micro_bit::setServoPulseUs help=pins/serial-set-pulse weight=19
2016-03-10 23:01:04 +01:00
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
export function servoSetPulse(pin: AnalogPin, micros: number): void { }
2016-03-10 23:01:04 +01:00
/**
* Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc.
* @param value value to map in ranges
* @param fromLow the lower bound of the value's current range
* @param fromHigh the upper bound of the value's current range, eg: 1023
* @param toLow the lower bound of the value's target range
* @param toHigh the upper bound of the value's target range, eg: 4
*/
2016-03-22 06:13:39 +01:00
//% help=pins/map weight=15
2016-03-10 23:01:04 +01:00
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;
}
/**
* Sets the pin used when using `pins->analog pitch`.
* @param name TODO
*/
2016-03-22 06:13:39 +01:00
//% shim=micro_bit::enablePitch help=pins/analog-set-pitch weight=12
export function analogSetPitchPin(name: AnalogPin): void { }
2016-03-10 23:01:04 +01:00
/**
* Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @param frequency TODO
* @param ms TODO
*/
2016-03-22 06:13:39 +01:00
//% shim=micro_bit::pitch help=pins/analog-pitch weight=14 async
2016-03-10 23:01:04 +01:00
export function analogPitch(frequency: number, ms: number): void { }
}