Skip to content

Commit

Permalink
move rgb led to MBitMore
Browse files Browse the repository at this point in the history
  • Loading branch information
Amerlander committed Apr 29, 2024
1 parent d6668e3 commit 24f555d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 68 deletions.
11 changes: 1 addition & 10 deletions libs/core/_locales/core-jsdoc-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,13 @@
"_py.range|param|stop": "The value to end the sequence before. This value will not show up in the result",
"_py.slice": "Returns a section of an array according to python's extended slice syntax",
"_py.stringSlice": "Returns a section of a string according to python's extended slice syntax",
"basic": "Provides access to basic micro:bit functionality.\n\nProvides access to basic calliope mini functionality.",
"basic": "Provides access to basic micro:bit functionality.",
"basic.clearScreen": "Turn off all LEDs",
"basic.forever": "Repeats the code forever in the background. On each iteration, allows other codes to run.",
"basic.pause": "Pause for the specified time in milliseconds",
"basic.pause|param|ms": "how long to pause for, eg: 100, 200, 500, 1000, 2000",
"basic.plotLeds": "Draws an image on the LED screen.",
"basic.plotLeds|param|leds": "pattern of LEDs to turn on/off",
"basic.setLedColor": "Sets the color on the built-in RGB LED. Set to 0 to turn off.",
"basic.setLedColorDal": "Sets the color on the built-in RGB LED. Set to 0 to turn off.",
"basic.setLedColorsCodal": "Sets the color on the built-in RGB LED. Set to 0 to turn off.",
"basic.setLedColorsCodal|param|brightness": "The LED brightness in percent.",
"basic.setLedColorsCodal|param|color1": "The color of the first LED in RGB format (e.g., 0xFF0000 for red).",
"basic.setLedColorsCodal|param|color2": "The second LED color.",
"basic.setLedColorsCodal|param|color3": "The third LED color.",
"basic.setLedColor|param|color": "The color of the LED in RGB format (e.g., 0xFF0000 for red).",
"basic.showAnimation": "Shows a sequence of LED screens as an animation.",
"basic.showAnimation|param|interval": "time in milliseconds between each redraw",
"basic.showAnimation|param|leds": "pattern of LEDs to turn on/off",
Expand All @@ -283,7 +275,6 @@
"basic.showString": "Display text on the display, one character at a time. If the string fits on the screen (i.e. is one letter), does not scroll.",
"basic.showString|param|interval": "how fast to shift characters; eg: 150, 100, 200, -100",
"basic.showString|param|text": "the text to scroll on the screen, eg: \"Hello!\"",
"basic.turnRgbLedOff": "Sets the color on the built-in RGB LED. Set to 0 to turn off.",
"console": "Reading and writing data to the console output.",
"console.addListener": "Adds a listener for the log messages",
"console.inspect": "Convert any object or value to a string representation",
Expand Down
3 changes: 0 additions & 3 deletions libs/core/_locales/core-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,11 @@
"basic.clearScreen|block": "clear screen",
"basic.forever|block": "forever",
"basic.pause|block": "pause (ms) %pause",
"basic.setLedColor|block": "set LED to %color=colorNumberPicker",
"basic.showArrow|block": "show arrow %i=device_arrow",
"basic.showIcon|block": "show icon %i",
"basic.showLeds|block": "show leds",
"basic.showNumber|block": "show|number %number",
"basic.showString|block": "show|string %text",
"basic.turnRgbLedOff|block": "turn built-in LED off",
"basic|block": "basic",
"console|block": "console",
"control.deviceName|block": "device name",
Expand Down Expand Up @@ -514,7 +512,6 @@
"{id:group}Operations": "Operations",
"{id:group}Pins": "Pins",
"{id:group}Pulse": "Pulse",
"{id:group}RGB LED": "RGB LED",
"{id:group}Read": "Read",
"{id:group}SPI": "SPI",
"{id:group}Servo": "Servo",
Expand Down
2 changes: 0 additions & 2 deletions libs/core/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,6 @@ declare namespace serial {
//% block="long pressed"
LongPressed = 4, // MICROBIT_BUTTON_EVT_LONG_CLICK
}
declare namespace basic {
}


declare const enum TouchTargetMode {
Expand Down
1 change: 0 additions & 1 deletion libs/core/pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"light.cpp",
"logo.cpp",
"loops.ts",
"rgbled.cpp",
"touchmode.cpp",
"soundexpressions.ts",
"soundexpressions.cpp",
Expand Down
52 changes: 0 additions & 52 deletions libs/core/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,58 +1280,6 @@ declare namespace input {
//% help="input/logo-is-pressed" shim=input::logoIsPressed
function logoIsPressed(): boolean;
}


/**
* Provides access to basic calliope mini functionality.
*/

declare namespace basic {

/**
* Sets the color on the built-in RGB LED. Set to 0 to turn off.
*/
//% blockId=device_turn_rgb_led_off block="turn built-in LED off"
//% help=basic/turn-rgb-led-off
//% weight=10
//% group="RGB LED"
//% advanced=true shim=basic::turnRgbLedOff
function turnRgbLedOff(): void;

/**
* Sets the color on the built-in RGB LED. Set to 0 to turn off.
* @param color1 The color of the first LED in RGB format (e.g., 0xFF0000 for red).
*/
//% blockId=device_set_led_colors-dal
//% hidden=1 shim=basic::setLedColorDal
function setLedColorDal(color: int32): void;

/**
* Sets the color on the built-in RGB LED. Set to 0 to turn off.
* @param color1 The color of the first LED in RGB format (e.g., 0xFF0000 for red).
* @param color2 The second LED color.
* @param color3 The third LED color.
* @param brightness The LED brightness in percent.
*/
//% blockId=device_set_led_colors-codal brightness.defl=20 shim=basic::setLedColorsCodal
function setLedColorsCodal(color1: int32, color2: int32, color3: int32, brightness?: int32): void;

/**
* Sets the color on the built-in RGB LED. Set to 0 to turn off.
* @param color The color of the LED in RGB format (e.g., 0xFF0000 for red).
*/
//% help=basic/set-led-color
//% blockId=device_set_led_color
//% block="set LED to %color=colorNumberPicker"
//% expandableArgumentMode="toggle"
//%
//%
//%
//%
//% weight=10
//% group="RGB LED" color.defl=0xff0000 shim=basic::setLedColor
function setLedColor(color?: int32): void;
}
declare namespace pins {

/**
Expand Down
1 change: 1 addition & 0 deletions libs/scratch/MbitMoreCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum MbitMoreCommand // 3 bits (0x00..0x07)
CMD_DISPLAY = 0x02,
CMD_AUDIO = 0x03,
CMD_DATA = 0x04,
CMD_RGB = 0x05,
};

enum MbitMorePinCommand
Expand Down
19 changes: 19 additions & 0 deletions libs/scratch/MbitMoreDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,25 @@ void MbitMoreDevice::onSerialConnected() {
*/
void MbitMoreDevice::onCommandReceived(uint8_t *data, size_t length) {
const int command = (data[0] >> 5);
if(command == MbitMoreCommand::CMD_RGB) {
#if MICROBIT_CODAL
uint8_t rgbBuffer[9] = {0};
memset(rgbBuffer, 0, sizeof(rgbBuffer)); // Clear the buffer
rgbBuffer[0] = data[1] * 20 / 100;
rgbBuffer[1] = data[2] * 20 / 100;
rgbBuffer[2] = data[3] * 20 / 100;
rgbBuffer[3] = data[4] * 20 / 100;
rgbBuffer[4] = data[5] * 20 / 100;
rgbBuffer[5] = data[6] * 20 / 100;
rgbBuffer[6] = data[7] * 20 / 100;
rgbBuffer[7] = data[8] * 20 / 100;
rgbBuffer[8] = data[9] * 20 / 100;
neopixel_send_buffer(uBit.io.RGB, rgbBuffer, sizeof(rgbBuffer));
#else
uBit.rgb.setColour(data[1], data[2], data[3], 0);
#endif
}
else
if (command == MbitMoreCommand::CMD_DISPLAY) {
const int displayCommand = data[0] & 0b11111;
if (displayCommand == MbitMoreDisplayCommand::TEXT) {
Expand Down
1 change: 1 addition & 0 deletions libs/scratch/enums.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CMD_DISPLAY = 0x02,
CMD_AUDIO = 0x03,
CMD_DATA = 0x04,
CMD_RGB = 0x05,
}


Expand Down

0 comments on commit 24f555d

Please sign in to comment.