pxt-calliope/libs/core/basic.cpp
Amerlander 3e0c9b43a2
V4 updates for beta testing (#147)
* 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

* Fix Sound and replace AnalogPin.P0

* remove approved extensions

* V4 Updates from remote Repo

* locales

* add storage functions

* fix storage functions

* fix int/float values

* decrease decimal precision

* reorder blocks

* Update BLE Settings and Storage Blocks

* Fetch MicroBit changes up to v4.0.18

* Update timing for LED Matrix usage

* use 32kb ram (mini v2)

* resize gatt table

* Revert "use 32kb ram (mini v2)"

This reverts commit 4b15592f0f.

* fix missleading indentation

* add support for 32kb and 16kb ram

* only MIT extensions in preferredRepos

* remove extensions without MIT License file

* add updated extensions

* add extensions with MIT license

Co-authored-by: Juri <gitkraken@juriwolf.de>
Co-authored-by: Juri <info@juriwolf.de>
2022-03-22 09:36:19 -07:00

150 lines
4.2 KiB
C++

#include "pxt.h"
/**
* Provides access to basic micro:bit functionality.
*/
namespace basic {
/**
* Draws an image on the LED screen.
* @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing
*/
//% help=basic/show-leds
//% weight=85 blockGap=8
//% imageLiteral=1 async
//% blockId=device_show_leds
//% block="show leds" icon="\uf00a"
//% parts="ledmatrix"
//% group="LED matrix"
void showLeds(ImageLiteral_ leds, int interval = 400) {
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
}
/**
* 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.
* @param text the text to scroll on the screen, eg: "hi!"
* @param interval how fast to shift characters; eg: 50, 100, 150, 200
*/
//% help=basic/show-string
//% weight=100 blockGap=16
//% block="show|string %text || in an interval of %interval ms"
//% async
//% blockId=device_print_message
//% parts="ledmatrix"
//% text.shadowOptions.toString=true
//% expandableArgumentMode="toggle"
//% interval.defl=80
//% group="LED matrix"
void showString(String text, int interval = 80) {
if (interval <= 0)
interval = 1;
int l = text ? text->getUTF8Size() : 0;
if (l == 0) {
uBit.display.clear();
fiber_sleep(interval * 5);
} else if (l > 1) {
uBit.display.scroll(MSTR(text), interval);
} else {
uBit.display.printChar(text->getUTF8Data()[0], interval * 5);
}
}
/**
* Shows a sequence of LED screens as an animation.
* @param leds pattern of LEDs to turn on/off
* @param interval time in milliseconds between each redraw
*/
//% help=basic/show-animation weight=83 imageLiteral=1 async
//% parts="ledmatrix"
//% group="LED matrix"
void showAnimation(ImageLiteral_ leds, int interval = 400) {
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0, 0);
}
/**
* Draws an image on the LED screen.
* @param leds pattern of LEDs to turn on/off
*/
//% help=basic/plot-leds weight=80
//% parts="ledmatrix"
//% group="LED matrix"
void plotLeds(ImageLiteral_ leds) {
MicroBitImage i(imageBytes(leds));
uBit.display.print(i, 0, 0, 0, 0);
}
/**
* Turn off all LEDs
*/
//% help=basic/clear-screen weight=75
//% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix"
//% group="LED matrix"
//% advanced=true
void clearScreen() {
uBit.display.image.clear();
}
/**
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=basic/forever weight=55 blockGap=16 blockAllowMultiple=1 afterOnStart=true
//% blockId=device_forever block="forever" icon="\uf01e"
//% group="Control"
void forever(Action a) {
runForever(a);
}
/**
* Pause for the specified time in milliseconds
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
*/
//% help=basic/pause weight=50
//% async block="pause (ms) %pause" blockGap=16
//% blockId=device_pause icon="\uf110"
//% pause.shadow=timePicker
//% group="Control"
void pause(int ms) {
fiber_sleep(ms);
}
/**
* Sets the color on the build-in LED. Set to 0 to turn off.
*/
//% blockId=device_set_led_color
//% block="set led to %color=colorNumberPicker"
//% weight=10
//% group="RGB LED"
void setLedColor(int color) {
if (!color) {
uBit.rgb.off();
return;
}
int w = (color >> 24) & 0xFF;
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color) & 0xFF;
uBit.rgb.setColour(r,g,b,w);
}
/**
* Sets the color on the build-in LED. Set to 0 to turn off.
*/
//% blockId=device_turn_rgb_led_off block="turn build-in LED off"
//% weight=10
//% group="RGB LED"
//% advanced=true
void turnRgbLedOff() {
uBit.rgb.off();
}
}