pxt-calliope/libs/core/input.ts
Amerlander 918af4f3ac
Bump V3.0.22 (#110)
* change simulator svg

* change radio image

* Remove google fonts cdn

* change color of 'advanced' button

* font fix

* font fix 2

* display fix

* change fullsceen simulator bg

* Continuous servo

* handle continuous state

* adding shims

* update rendering for continuous servos

* fixing sim

* fix sig

* typo

* fix sim

* bump pxt

* bump pxt

* rerun travis

* Input blocks revision

- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function

* update input blocks in docs and tests

* remove device_pin_release block

* Hide DAL.x behind Enum

* bring back deprecated blocks, but hide them

* shims and locales files

* fix input.input. typing

* remove buildpr

* bump V3

* update simulator aspect ratio

* add Loudness Block

* revoke loudness block

* Adds soundLevel

To be replaced by pxt-common-packages when DAL is updated.

* Remove P0 & P3 from AnalogPin

Co-authored-by: Juri <gitkraken@juriwolf.de>
2020-09-08 02:04:25 -07:00

104 lines
2.6 KiB
TypeScript

/**
* Events and data from sensors
*/
//% color=#C90072 weight=99
namespace input {
/**
* Attaches code to run when the screen is facing up.
* @param body TODO
*/
//% help=input/on-screen-up
export function onScreenUp(body: () => void): void {
onGesture(Gesture.ScreenUp, body);
}
/**
* Attaches code to run when the screen is facing down.
* @param body TODO
*/
//% help=input/on-screen-down
export function onScreenDown(body: () => void): void {
onGesture(Gesture.ScreenDown, body);
}
/**
* Attaches code to run when the device is shaken.
* @param body TODO
*/
//% deprecated=true
//% help=input/on-shake
export function onShake(body: () => void): void {
onGesture(Gesture.Shake, body);
}
/**
* Attaches code to run when the logo is oriented upwards and the board is vertical.
* @param body TODO
*/
//% help=input/on-logo-up
export function onLogoUp(body: () => void): void {
onGesture(Gesture.LogoUp, body);
}
/**
* Attaches code to run when the logo is oriented downwards and the board is vertical.
* @param body TODO
*/
//% help=input/on-logo-down
export function onLogoDown(body: () => void): void {
onGesture(Gesture.LogoDown, body);
}
/**
* Obsolete, use input.calibrateCompass instead.
*/
//% weight=0 help=input/calibrate-compass
export function calibrate() {
input.calibrateCompass();
}
/**
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true
export function runningTime() {
return control.millis();
}
/**
* Gets the number of microseconds elapsed since power on.
*/
//% help=input/running-time-micros weight=49
//% blockId=device_get_running_time_micros block="running time (micros)"
//% advanced=true
export function runningTimeMicros() {
return control.micros();
}
/**
* gets the level of loudness in 0-100%
*/
//% blockId="loudness"
//% block="Loudness"
export function soundLevel(): number {
let value = 0
let max = 0
let min = 1023
for (let index = 0; index < 32; index++) {
value = pins.analogReadPin(AnalogPin.MIC)
if (value > max) {
max = value
} else if (value < min) {
min = value
}
}
value = (max - min) * 977 / 10000
return value
}
}