2016-09-27 22:35:48 +02:00
|
|
|
/**
|
|
|
|
Well known colors
|
|
|
|
*/
|
|
|
|
enum Colors {
|
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=red
|
2016-10-11 20:41:51 +02:00
|
|
|
Red = 0x00FF0000,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=orange
|
2016-10-11 20:41:51 +02:00
|
|
|
Orange = 0x00FFA500,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=yellow
|
2016-10-11 20:41:51 +02:00
|
|
|
Yellow = 0x00FFFF00,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=green
|
2016-10-11 20:41:51 +02:00
|
|
|
Green = 0x0000FF00,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=blue
|
2016-10-11 20:41:51 +02:00
|
|
|
Blue = 0x000000FF,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=indigo
|
2016-10-11 20:41:51 +02:00
|
|
|
Indigo = 0x004b0082,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=violet
|
2016-10-11 20:41:51 +02:00
|
|
|
Violet = 0x008a2be2,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=purple
|
2016-10-11 20:41:51 +02:00
|
|
|
Purple = 0x00FF00FF,
|
2016-09-27 22:35:48 +02:00
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=white
|
2019-12-02 05:58:26 +01:00
|
|
|
White = 0xFFFFFFFF,
|
|
|
|
//% blockIdentity=basic.color
|
|
|
|
//% block=off
|
|
|
|
Off = 0x00000000,
|
2016-09-27 22:35:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides access to basic micro:bit functionality.
|
|
|
|
*/
|
2022-03-22 17:36:19 +01:00
|
|
|
//% color=#54C9C9 weight=100 icon="\uf00a"
|
|
|
|
//% groups=['LED matrix', 'Control', 'RGB LED', 'others']
|
2016-09-27 22:35:48 +02:00
|
|
|
namespace basic {
|
2022-03-22 17:36:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll a number on the screen. If the number fits on the screen (i.e. is a single digit), do not scroll.
|
|
|
|
* @param interval speed of scroll; eg: 50, 100, 150, 200
|
|
|
|
*/
|
|
|
|
//% help=basic/show-number
|
|
|
|
//% weight=95
|
|
|
|
//% blockId=device_show_number
|
|
|
|
//% block="show|number %number || in an interval of %interval ms" blockGap=8
|
|
|
|
//% async
|
|
|
|
//% parts="ledmatrix"
|
|
|
|
//% expandableArgumentMode="toggle"
|
|
|
|
//% interval.defl=80
|
|
|
|
//% group="LED matrix"
|
|
|
|
export function showNumber(value: number, interval?: number) {
|
|
|
|
showString(Math.roundWithPrecision(value, 2).toString(), interval);
|
|
|
|
}
|
2019-12-02 05:58:26 +01:00
|
|
|
|
2016-09-27 22:35:48 +02:00
|
|
|
/**
|
|
|
|
* Converts the color name to a number
|
|
|
|
*/
|
|
|
|
//% blockId=color_id block="%c" shim=TD_ID
|
2022-03-22 17:36:19 +01:00
|
|
|
//% group="RGB LED"
|
|
|
|
//% weight=1
|
|
|
|
//% deprecated=true
|
2016-09-27 22:35:48 +02:00
|
|
|
export function color(c: Colors): number {
|
|
|
|
return c;
|
|
|
|
}
|
2016-10-11 20:41:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts red, green, blue channels into a RGB color
|
|
|
|
* @param red value of the red channel between 0 and 255. eg: 255
|
|
|
|
* @param green value of the green channel between 0 and 255. eg: 255
|
|
|
|
* @param blue value of the blue channel between 0 and 255. eg: 255
|
|
|
|
*/
|
2022-03-22 17:36:19 +01:00
|
|
|
//% weight=3
|
|
|
|
//% blockId="core_rgb" block="red %red|green %green|blue %blue"
|
|
|
|
//% group="RGB LED"
|
|
|
|
export function rgb(red: number, green: number, blue: number): number {
|
|
|
|
return ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | (blue & 0xFF);
|
2016-10-11 20:41:51 +02:00
|
|
|
}
|
2022-03-22 17:36:19 +01:00
|
|
|
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
/**
|
2022-03-22 17:36:19 +01:00
|
|
|
* Converts red, green, blue channels into a RGB color
|
|
|
|
* @param red value of the red channel between 0 and 255. eg: 255
|
|
|
|
* @param green value of the green channel between 0 and 255. eg: 255
|
|
|
|
* @param blue value of the blue channel between 0 and 255. eg: 255
|
|
|
|
* @param white value of the white channel between 0 and 255. eg: 0
|
2019-12-02 05:58:26 +01:00
|
|
|
*/
|
2022-03-22 17:36:19 +01:00
|
|
|
//% weight=2
|
|
|
|
//% blockId="core_rgbw" block="red %red|green %green|blue %blue|white %white"
|
|
|
|
//% group="RGB LED"
|
|
|
|
//% deprecated=true
|
|
|
|
export function rgbw(red: number, green: number, blue: number, white:number): number {
|
|
|
|
return ((white & 0xFF) << 24) | ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | (blue & 0xFF);
|
2019-12-02 05:58:26 +01:00
|
|
|
}
|
2022-03-22 17:36:19 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
}
|
2020-09-08 11:04:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause for the specified time in milliseconds
|
|
|
|
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
|
|
|
|
*/
|
2022-03-22 17:36:19 +01:00
|
|
|
function pause(ms: number): void {
|
2020-09-08 11:04:25 +02:00
|
|
|
basic.pause(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Repeats the code forever in the background. On each iteration, allows other codes to run.
|
|
|
|
* @param body code to execute
|
|
|
|
*/
|
|
|
|
function forever(a: () => void): void {
|
|
|
|
basic.forever(a);
|
2022-03-22 17:36:19 +01:00
|
|
|
}
|