Compare commits

...

16 Commits

Author SHA1 Message Date
4f741981e3 1.0.18 2017-12-14 11:22:23 -08:00
e93ae5e01b adjusting old styles 2017-12-14 11:21:55 -08:00
baee733aad 1.0.17 2017-12-14 11:06:09 -08:00
13f252c6f4 support for icons (#15) 2017-12-14 11:04:59 -08:00
694c24406f 1.0.16 2017-12-14 11:01:07 -08:00
2250aa9d4b Upgrades (#14)
* enable tracing

* more config adjustments

* upgrading images

* upgrading input

* upgrading led

* upgraded pins api

* upgrade runtime

* upgrading pxt.h

* upgrading basic.cpp

* upgraded control

* upgraded control.ts

* upgrading core.cpp

* updating shims

* fixing merge issues

* upgrading BLE config
2017-12-14 11:00:47 -08:00
a1f1911eb0 Merge branch 'master' of https://github.com/Microsoft/pxt-calliope 2017-12-14 10:40:07 -08:00
a5f8e9a643 upgrading game apis (#13) 2017-12-14 10:34:32 -08:00
5a6cbf2639 upgrading music APIs (#12) 2017-12-14 10:34:04 -08:00
ff11e70c84 more config adjustments 2017-12-14 09:57:49 -08:00
a6487f62c0 enable tracing 2017-12-14 09:53:08 -08:00
63047454cb 1.0.15 2017-12-14 08:59:49 -08:00
1373c2616c enabling functions and arrays 2017-12-14 08:59:39 -08:00
739584e465 bump master to 1.0.13 2017-12-14 05:30:11 -08:00
73e5263a0a 1.0.14 2017-12-14 05:28:20 -08:00
9c24e5f87f bump pxt-core to 0.14.32, 2017-12-14 05:28:11 -08:00
70 changed files with 1812 additions and 809 deletions

View File

@ -1,3 +1,3 @@
{
"appref": "v0.8.30"
"appref": "v1.0.13"
}

View File

@ -17,44 +17,18 @@
"config": {
"microbit-dal": {
"bluetooth": {
"enabled": 1,
"pairing_mode": 1,
"private_addressing": 0,
"open": 0,
"whitelist": 1,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 0,
"device_info_service": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM",
"eddystone_url": 1,
"eddystone_uid": 1
"enabled": 1
}
}
},
"optionalConfig": {
"microbit-dal": {
"bluetooth": {
"private_addressing": 0,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 1,
"device_info_service": 1,
"eddystone_url": 1,
"eddystone_uid": 1,
"open": 0,
"pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
},
"gatt_table_size": "0x700"
}
},
"userConfigs": [
{
"description": "Unsecure: Anyone can connect via Bluetooth.",
"description": "No Pairing Required: Anyone can connect via Bluetooth.",
"config": {
"microbit-dal": {
"bluetooth": {
@ -67,7 +41,7 @@
}
},
{
"description": "JustWorks pairing (default): Button press to pair.",
"description": "JustWorks pairing (default): Pairing is automatic once the pairing is initiated.",
"config": {
"microbit-dal": {
"bluetooth": {
@ -80,7 +54,7 @@
}
},
{
"description": "Passkey pairing: Button press and 6 digit key to pair.",
"description": "Passkey pairing: Pairing requires 6 digit key to pair.",
"config": {
"microbit-dal": {
"bluetooth": {

View File

@ -58,6 +58,7 @@
"EventCreationMode": "How to create the event.",
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).",
"EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
"Gesture.EightG": "Raised when a 8G shock is detected",
"Gesture.FreeFall": "Raised when the board is falling!",
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
"Gesture.LogoUp": "Raised when the logo is upward and the screen is vertical",
@ -138,7 +139,12 @@
"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",
"basic.showArrow": "Shows an arrow on screent",
"basic.showArrow|param|direction": "the direction of the arrow",
"basic.showArrow|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showIcon": "Draws the selected icon on the LED screen",
"basic.showIcon|param|icon": "the predifined icon id",
"basic.showIcon|param|interval": "the amount of time (milliseconds) to show the icon. Default is 600.",
"basic.showLeds": "Draws an image on the LED screen.",
"basic.showLeds|param|interval": "time in milliseconds to pause after drawing",
"basic.showLeds|param|leds": "the pattern of LED to turn on/off",
@ -167,13 +173,14 @@
"control.waitMicros": "Blocks the current fiber for the given microseconds",
"control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
"game": "A single-LED sprite game engine",
"game.LedSprite": "A game sprite rendered as a single LED",
"game.LedSprite.blink": "Reports the ``blink`` duration of a sprite",
"game.LedSprite.brightness": "Reports the ``brightness` of a sprite on the LED screen",
"game.LedSprite.change": "Changes a property of the sprite",
"game.LedSprite.changeBlinkBy": "Changes the ``blink`` duration by the given amount of millisecons",
"game.LedSprite.changeBlinkBy|param|ms": "TODO",
"game.LedSprite.changeBrightnessBy": "Changes the ``y`` position by the given amount",
"game.LedSprite.changeBrightnessBy|param|value": "TODO",
"game.LedSprite.changeBrightnessBy|param|value": "the value to change brightness",
"game.LedSprite.changeDirectionBy": "Changes the ``direction`` position by the given amount by turning right",
"game.LedSprite.changeDirectionBy|param|angle": "TODO",
"game.LedSprite.changeXBy": "Changes the ``x`` position by the given amount",
@ -182,19 +189,18 @@
"game.LedSprite.changeYBy|param|y": "TODO",
"game.LedSprite.change|param|property": "the name of the property to change",
"game.LedSprite.change|param|value": "amount of change, eg: 1",
"game.LedSprite.delete": "Deletes the sprite from the game engine. All further operation of the sprite will not have any effect.",
"game.LedSprite.delete|param|sprite": "TODO",
"game.LedSprite.delete": "Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.",
"game.LedSprite.direction": "Reports the current direction of a sprite",
"game.LedSprite.get": "Gets a property of the sprite",
"game.LedSprite.get|param|property": "the name of the property to change",
"game.LedSprite.goTo": "Go to this position on the screen",
"game.LedSprite.goTo|param|x": "TODO",
"game.LedSprite.goTo|param|y": "TODO",
"game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage, then bounce away.",
"game.LedSprite.isTouching": "Reports true if sprite is touching specified sprite",
"game.LedSprite.ifOnEdgeBounce": "If touching the edge of the stage and facing towards it, then turn away.",
"game.LedSprite.isTouching": "Reports true if sprite has the same position as specified sprite",
"game.LedSprite.isTouchingEdge": "Reports true if sprite is touching an edge",
"game.LedSprite.isTouching|param|other": "TODO",
"game.LedSprite.move": "Move a certain number of LEDs",
"game.LedSprite.move": "Move a certain number of LEDs in the current direction",
"game.LedSprite.move|param|leds": "number of leds to move, eg: 1, -1",
"game.LedSprite.off": "Turns off the sprite (on by default)",
"game.LedSprite.on": "Turns on the sprite (on by default)",
@ -202,7 +208,7 @@
"game.LedSprite.setBlink": "Sets the blink duration interval in millisecond.",
"game.LedSprite.setBlink|param|ms": "TODO",
"game.LedSprite.setBrightness": "Set the ``brightness`` of a sprite",
"game.LedSprite.setBrightness|param|brightness": "TODO",
"game.LedSprite.setBrightness|param|brightness": "the brightness from 0 (off) to 255 (on), eg: 255.",
"game.LedSprite.setDirection": "Set the direction of the current sprite, rounded to the nearest multiple of 45",
"game.LedSprite.setDirection|param|degrees": "TODO",
"game.LedSprite.setX": "Set the ``x`` position of a sprite",
@ -221,28 +227,31 @@
"game.LedSprite.y": "Reports the ``y`` position of a sprite on the LED screen",
"game.addLife": "Adds life points to the current life",
"game.addLife|param|lives": "TODO",
"game.addScore": "Adds points to the current score",
"game.addScore": "Adds points to the current score and shows an animation",
"game.addScore|param|points": "amount of points to change, eg: 1",
"game.createSprite": "Creates a new LED sprite pointing to the right.",
"game.createSprite|param|x": "sprite horizontal coordinate, eg: 2",
"game.createSprite|param|y": "sprite vertical coordinate, eg: 2",
"game.currentTime": "Gets the remaining time (since `start countdown`) or current time (since the device started or `start stopwatch`) in milliseconds.",
"game.gameOver": "Displays a game over animation.",
"game.gameOver": "Displays a game over animation and the score.",
"game.invalidSprite": "Gets an invalid sprite; used to initialize locals.",
"game.isGameOver": "Indicates if the game is display the game over sequence.",
"game.isPaused": "Indicates if the game rendering is paused to allow other animations",
"game.isRunning": "Gets a value indicating if the game is still running. Returns `false` if game over.",
"game.level": "Gets the current level",
"game.levelUp": "Increments the level and display a message.",
"game.life": "Gets the current life",
"game.pause": "Pauses the game rendering engine to allow other animations",
"game.removeLife": "Removes some life",
"game.removeLife|param|life": "TODO",
"game.resume": "Resumes the game rendering engine",
"game.score": "Gets the current score",
"game.setLife": "Sets the current life value",
"game.setLife|param|value": "TODO",
"game.setScore": "Sets the current score value",
"game.setScore|param|value": "TODO",
"game.setScore|param|value": "new score value.",
"game.showScore": "Displays the score on the screen.",
"game.startCountdown": "Starts a game countdown timer",
"game.startCountdown": "Shows an animation, then starts a game countdown timer, which causes Game Over when it reaches 0",
"game.startCountdown|param|ms": "countdown duration in milliseconds, eg: 10000",
"game.startStopwatch": "Starts a stopwatch timer. `current time` will return the elapsed time.",
"images": "Creation, manipulation and display of LED images.",
@ -252,26 +261,28 @@
"input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)",
"input.acceleration|param|dimension": "TODO",
"input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.",
"input.calibrate": "Obsolete, compass calibration is automatic.",
"input.buttonIsPressed|param|button": "the button to query the request, eg: Button.A",
"input.calibrateCompass": "Obsolete, compass calibration is automatic.",
"input.compassHeading": "Get the current compass heading in degrees.",
"input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.",
"input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.",
"input.magneticForce|param|dimension": "TODO",
"input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed",
"input.onButtonPressed|param|body": "TODO",
"input.onButtonPressed|param|button": "TODO",
"input.onButtonPressed": "Do something when a button (A, B or both A+B) is pushed down and released again.",
"input.onButtonPressed|param|body": "code to run when event is raised",
"input.onButtonPressed|param|button": "the button that needs to be pressed",
"input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).",
"input.onGesture|param|body": "TODO",
"input.onGesture|param|body": "code to run when gesture is raised",
"input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake",
"input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.",
"input.onLogoDown|param|body": "TODO",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onLogoUp|param|body": "TODO",
"input.onPinPressed": "Do something when a pin is pressed.",
"input.onPinPressed": "Do something when a pin is touched and released again (while also touching the GND pin).",
"input.onPinPressed|param|body": "the code to run when the pin is pressed",
"input.onPinPressed|param|name": "the pin that needs to be pressed",
"input.onPinPressed|param|name": "the pin that needs to be pressed, eg: TouchPin.P0",
"input.onPinReleased": "Do something when a pin is released.",
"input.onPinReleased|param|body": "the code to run when the pin is released",
"input.onPinReleased|param|name": "the pin that needs to be released",
"input.onPinReleased|param|name": "the pin that needs to be released, eg: TouchPin.P0",
"input.onScreenDown": "Attaches code to run when the screen is facing down.",
"input.onScreenDown|param|body": "TODO",
"input.onScreenUp": "Attaches code to run when the screen is facing up.",
@ -279,15 +290,17 @@
"input.onShake": "Attaches code to run when the device is shaken.",
"input.onShake|param|body": "TODO",
"input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.",
"input.pinIsPressed|param|name": "pin used to detect the touch",
"input.pinIsPressed|param|name": "pin used to detect the touch, eg: TouchPin.P0",
"input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.",
"input.rotation|param|kind": "TODO",
"input.runningTime": "Gets the number of milliseconds elapsed since power on.",
"input.runningTimeMicros": "Gets the number of microseconds elapsed since power on.",
"input.setAccelerometerRange": "Sets the accelerometer sample range in gravities.",
"input.setAccelerometerRange|param|range": "a value describe the maximum strengh of acceleration measured",
"input.temperature": "Gets the temperature in Celsius degrees (°C).",
"led": "Control of the LED screen.",
"led.brightness": "Get the screen brightness from 0 (off) to 255 (full bright).",
"led.displayMode": "Gets the current display mode",
"led.enable": "Turns on or off the display",
"led.fadeIn": "Fades in the screen display.",
"led.fadeIn|param|ms": "TODO",
@ -298,8 +311,12 @@
"led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.",
"led.plotBarGraph|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0",
"led.plotBarGraph|param|value": "current value to plot",
"led.plot|param|x": "TODO",
"led.plot|param|y": "TODO",
"led.plotBrightness": "Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
"led.plotBrightness|param|brightness": "the brightness from 0 (off) to 255 (bright), eg:255",
"led.plotBrightness|param|x": "the horizontal coordinate of the LED starting at 0",
"led.plotBrightness|param|y": "the vertical coordinate of the LED starting at 0",
"led.plot|param|x": "the horizontal coordinate of the LED starting at 0",
"led.plot|param|y": "the vertical coordinate of the LED starting at 0",
"led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.",
"led.point|param|x": "TODO",
"led.point|param|y": "TODO",
@ -321,43 +338,52 @@
"motors.motorCommand": "Send break, coast or sleep commands to the motor. Has no effect in dual-motor mode.",
"motors.motorPower": "Turns on the motor at a certain percent of power. Switches to single motor mode!",
"motors.motorPower|param|power": "%percent of power sent to the motor. Negative power goes backward. eg: 50",
"music": "Generation of music tones through pin ``P0``.",
"music": "Generation of music tones.",
"music.beat": "Returns the duration of a beat in milli-seconds",
"music.beginMelody": "Starts playing a melody.\nNotes are expressed as a string of characters with this format: NOTE[octave][:duration]",
"music.beginMelody|param|melodyArray": "the melody array to play, eg: ['g5:1']",
"music.beginMelody|param|options": "melody options, once / forever, in the foreground / background",
"music.builtInMelody": "Gets the melody array of a built-in melody.",
"music.changeTempoBy": "Change the tempo by the specified amount",
"music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20",
"music.noteFrequency": "Gets the frequency of a note.",
"music.noteFrequency|param|name": "the note name",
"music.playTone": "Plays a tone through ``speaker`` for the given duration.",
"music.noteFrequency|param|name": "the note name, eg: Note.C",
"music.onEvent": "Registers code to run on various melody events",
"music.playTone": "Plays a tone through pin ``P0`` for the given duration.",
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.playTone|param|ms": "tone duration in milliseconds (ms)",
"music.rest": "Rests (plays nothing) for a specified time through pin ``P0``.",
"music.rest|param|ms": "rest duration in milliseconds (ms)",
"music.ringTone": "Plays a tone through ``speaker``.",
"music.ringTone": "Plays a tone through pin ``P0``.",
"music.ringTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.setPlayTone": "Sets a custom playTone function for playing melodies",
"music.setTempo": "Sets the tempo to the specified amount",
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
"music.speakerPlayTone": "Plays a tone through ``speaker`` for the given duration.",
"music.speakerPlayTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.speakerPlayTone|param|ms": "tone duration in milliseconds (ms)",
"music.tempo": "Returns the tempo in beats per minute. Tempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play.",
"parseInt": "Convert A string to an integer.",
"pins": "Control currents in Pins for analog/digital signals, servos, i2c, ...",
"pins.analogPitch": "Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.",
"pins.analogPitch|param|frequency": "TODO",
"pins.analogPitch|param|ms": "TODO",
"pins.analogPitch|param|frequency": "frequency to modulate in Hz.",
"pins.analogPitch|param|ms": "duration of the pitch in milli seconds.",
"pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.",
"pins.analogReadPin|param|name": "pin to write to",
"pins.analogReadPin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.",
"pins.analogSetPeriod|param|micros": "period in micro seconds. eg:20000",
"pins.analogSetPeriod|param|name": "analog pin to set period to",
"pins.analogSetPitchPin": "Sets the pin used when using `pins->analog pitch`.",
"pins.analogSetPitchPin|param|name": "TODO",
"pins.analogSetPeriod|param|name": "analog pin to set period to, eg: AnalogPin.P0",
"pins.analogSetPitchPin": "Sets the pin used when using `analog pitch` or music.",
"pins.analogSetPitchPin|param|name": "pin to modulate pitch from",
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.analogWritePin|param|name": "pin name to write to",
"pins.analogWritePin|param|name": "pin name to write to, eg: AnalogPin.P0",
"pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0",
"pins.createBuffer": "Create a new zero-initialized buffer.",
"pins.createBuffer|param|size": "number of bytes in the buffer",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalReadPin|param|name": "pin to read from",
"pins.digitalReadPin|param|name": "pin to read from, eg: DigitalPin.P0",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
"pins.digitalWritePin|param|name": "pin to write to",
"pins.digitalWritePin|param|name": "pin to write to, eg: DigitalPin.P0",
"pins.digitalWritePin|param|value": "value to set on the pin, 1 eg,0",
"pins.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.",
"pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
@ -370,23 +396,31 @@
"pins.map|param|toLow": "the lower bound of the value's target range",
"pins.map|param|value": "value to map in ranges",
"pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.",
"pins.onPulsed|param|name": "digital pin to register to, eg: DigitalPin.P0",
"pins.onPulsed|param|pulse": "the value of the pulse, eg: PulseValue.High",
"pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.",
"pins.pulseIn": "Returns the duration of a pulse in microseconds",
"pins.pulseIn|param|name": "the pin which measures the pulse",
"pins.pulseIn|param|value": "the value of the pulse (default high)",
"pins.pulseIn|param|name": "the pin which measures the pulse, eg: DigitalPin.P0",
"pins.pulseIn|param|value": "the value of the pulse, eg: PulseValue.High",
"pins.servoSetPulse": "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.",
"pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500",
"pins.servoSetPulse|param|name": "pin name",
"pins.servoWritePin": "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).",
"pins.servoWritePin|param|name": "pin to write to",
"pins.servoWritePin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.servoWritePin|param|value": "angle or rotation speed, eg:180,90,0",
"pins.setEvents": "Configures the events emitted by this pin. Events can be subscribed to\nusing ``control.onEvent()``.",
"pins.setEvents|param|name": "pin to set the event mode on, eg: DigitalPin.P0",
"pins.setEvents|param|type": "the type of events for this pin to emit, eg: PinEventType.Edge",
"pins.setPull": "Configures the pull of this pin.",
"pins.setPull|param|name": "pin to set the pull mode on",
"pins.setPull|param|pull": "one of the mbed pull configurations: PullUp, PullDown, PullNone ",
"pins.setPull|param|name": "pin to set the pull mode on, eg: DigitalPin.P0",
"pins.setPull|param|pull": "one of the mbed pull configurations, eg: PinPullMode.PullUp",
"pins.sizeOf": "Get the size in bytes of specified number format.",
"pins.spiFormat": "Sets the SPI bits and mode",
"pins.spiFormat|param|bits": "the number of bits, eg: 8",
"pins.spiFormat|param|mode": "the mode, eg: 3",
"pins.spiFrequency": "Sets the SPI frequency",
"pins.spiFrequency|param|frequency": "the clock frequency, eg: 1000000",
"pins.spiPins": "Sets the MOSI, MISO, SCK pins used by the SPI instance",
"pins.spiWrite": "Write to the SPI slave and return the response",
"pins.spiWrite|param|value": "Data to be sent to the SPI slave",
"serial": "Reading and writing data over a serial connection.",

View File

@ -17,9 +17,19 @@
"Array.shift|block": "get and remove first value from %list",
"Array.unshift|block": "%list| insert %value| at beginning",
"Array|block": "Array",
"ArrowNames.East|block": "East",
"ArrowNames.NorthEast|block": "North East",
"ArrowNames.NorthWest|block": "North West",
"ArrowNames.North|block": "North",
"ArrowNames.SouthEast|block": "South East",
"ArrowNames.SouthWest|block": "South West",
"ArrowNames.South|block": "South",
"ArrowNames.West|block": "West",
"BaudRate.BaudRate115200|block": "115200",
"BaudRate.BaudRate56700|block": "57600",
"BaudRate.BaudRate9600|block": "9600",
"BeatFraction.Breve|block": "4",
"BeatFraction.Double|block": "2",
"BeatFraction.Eighth|block": "1/8",
"BeatFraction.Half|block": "1/2",
"BeatFraction.Quarter|block": "1/4",
@ -51,6 +61,8 @@
"DisplayMode.Greyscale|block": "greyscale",
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).",
"EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
"Gesture.EightG": "Raised when a 8G shock is detected",
"Gesture.EightG|block": "8g",
"Gesture.FreeFall": "Raised when the board is falling!",
"Gesture.FreeFall|block": "free fall",
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
@ -89,12 +101,12 @@
"IconNames.LeftTriangle|block": "left triangle",
"IconNames.Meh|block": "meh",
"IconNames.No|block": "no",
"IconNames.Pacman|block": "pac man",
"IconNames.Pitchfork|block": "pitchfork",
"IconNames.QuarterNote|block": "quarter note",
"IconNames.Rabbit|block": "rabbit",
"IconNames.Rollerskate|block": "roller skate",
"IconNames.Sad|block": "sad",
"IconNames.Scissors|block": "scissors",
"IconNames.Silly|block": "silly",
"IconNames.Skull|block": "skull",
"IconNames.SmallDiamond|block": "small diamond",
@ -121,10 +133,60 @@
"Math.randomBoolean|block": "pick random true or false",
"Math.random|block": "pick random 0 to %limit",
"Math|block": "Math",
"Melodies.BaDing|block": "ba ding",
"Melodies.Baddy|block": "baddy",
"Melodies.Birthday|block": "birthday",
"Melodies.Blues|block": "blues",
"Melodies.Chase|block": "chase",
"Melodies.Dadadadum|block": "dadadum",
"Melodies.Entertainer|block": "entertainer",
"Melodies.Funeral|block": "funereal",
"Melodies.Funk|block": "funk",
"Melodies.JumpDown|block": "jump down",
"Melodies.JumpUp|block": "jump up",
"Melodies.Nyan|block": "nyan",
"Melodies.Ode|block": "ode",
"Melodies.PowerDown|block": "power down",
"Melodies.PowerUp|block": "power up",
"Melodies.Prelude|block": "prelude",
"Melodies.Punchline|block": "punchline",
"Melodies.Ringtone|block": "ringtone",
"Melodies.Wawawawaa|block": "wawawawaa",
"Melodies.Wedding|block": "wedding",
"MelodyOptions.ForeverInBackground|block": "forever in background",
"MelodyOptions.Forever|block": "forever",
"MelodyOptions.OnceInBackground|block": "once in background",
"MelodyOptions.Once|block": "once",
"MesDpadButtonInfo.ADown|block": "A down",
"MesDpadButtonInfo.AUp|block": "A up",
"MesDpadButtonInfo.BDown|block": "B down",
"MesDpadButtonInfo.BUp|block": "B up",
"MesDpadButtonInfo.CDown|block": "C down",
"MesDpadButtonInfo.CUp|block": "C up",
"MesDpadButtonInfo.DDown|block": "D down",
"MesDpadButtonInfo.DUp|block": "D up",
"MesDpadButtonInfo._1Down|block": "1 down",
"MesDpadButtonInfo._1Up|block": "1 up",
"MesDpadButtonInfo._2Down|block": "2 down",
"MesDpadButtonInfo._2Up|block": "2 up",
"MesDpadButtonInfo._3Down|block": "3 down",
"MesDpadButtonInfo._3Up|block": "3 up",
"MesDpadButtonInfo._4Down|block": "4 down",
"MesDpadButtonInfo._4Up|block": "4 up",
"Motor.AB|block": "A and B",
"MotorCommand.Break|block": "break",
"MotorCommand.Coast|block": "coast",
"MotorCommand.Sleep|block": "sleep",
"MusicEvent.BackgroundMelodyEnded|block": "background melody ended",
"MusicEvent.BackgroundMelodyNotePlayed|block": "background melody note played",
"MusicEvent.BackgroundMelodyPaused|block": "background melody paused",
"MusicEvent.BackgroundMelodyRepeated|block": "background melody repeated",
"MusicEvent.BackgroundMelodyResumed|block": "background melody resumed",
"MusicEvent.BackgroundMelodyStarted|block": "background melody started",
"MusicEvent.MelodyEnded|block": "melody ended",
"MusicEvent.MelodyNotePlayed|block": "melody note played",
"MusicEvent.MelodyRepeated|block": "melody repeated",
"MusicEvent.MelodyStarted|block": "melody started",
"Note.CSharp3|block": "C#3",
"Note.CSharp4|block": "C#4",
"Note.CSharp5|block": "C#5",
@ -177,6 +239,7 @@
"control.waitMicros|block": "wait (µs)%micros",
"control|block": "control",
"game.LedSprite.change|block": "%sprite|change %property|by %value",
"game.LedSprite.delete|block": "delete %this",
"game.LedSprite.get|block": "%sprite|%property",
"game.LedSprite.ifOnEdgeBounce|block": "%sprite|if on edge, bounce",
"game.LedSprite.isTouchingEdge|block": "%sprite|touching edge?",
@ -187,7 +250,10 @@
"game.addScore|block": "change score by|%points",
"game.createSprite|block": "create sprite at|x: %x|y: %y",
"game.gameOver|block": "game over",
"game.pause|block": "pause",
"game.resume|block": "resume",
"game.score|block": "score",
"game.setScore|block": "set score %points",
"game.startCountdown|block": "start countdown|(ms) %duration",
"game|block": "game",
"images.arrowImage|block": "arrow image %i=device_arrow",
@ -198,21 +264,25 @@
"images|block": "images",
"input.acceleration|block": "acceleration (mg)|%NAME",
"input.buttonIsPressed|block": "button|%NAME|is pressed",
"input.calibrateCompass|block": "calibrate compass",
"input.compassHeading|block": "compass heading (°)",
"input.lightLevel|block": "light level",
"input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonPressed|block": "on button|%NAME|pressed",
"input.onGesture|block": "on |%NAME",
"input.onPinPressed|block": "on pin %NAME|pressed",
"input.onPinPressed|block": "on pin %name|pressed",
"input.onPinReleased|block": "on pin %NAME|released",
"input.pinIsPressed|block": "pin %NAME|is pressed",
"input.rotation|block": "rotation (°)|%NAME",
"input.runningTimeMicros|block": "running time (micros)",
"input.runningTime|block": "running time (ms)",
"input.setAccelerometerRange|block": "set accelerometer|range %range",
"input.temperature|block": "temperature (°C)",
"input|block": "input",
"led.brightness|block": "brightness",
"led.enable|block": "led enable %on",
"led.plotBarGraph|block": "plot bar graph of %value |up to %high",
"led.plotBrightness|block": "plot|x %x|y %y|brightness %brightness",
"led.plot|block": "plot|x %x|y %y",
"led.point|block": "point|x %x|y %y",
"led.setBrightness|block": "set brightness %value",
@ -225,8 +295,11 @@
"motors.motorPower|block": "motor on at %percent",
"motors|block": "motors",
"music.beat|block": "%fraction|beat",
"music.beginMelody|block": "start melody %melody=device_builtin_melody| repeating %options",
"music.builtInMelody|block": "%melody",
"music.changeTempoBy|block": "change tempo by (bpm)|%value",
"music.noteFrequency|block": "%note",
"music.onEvent|block": "music on %value",
"music.playTone|block": "play|tone %note=device_note|for %duration=device_beat",
"music.rest|block": "rest(ms)|%duration=device_beat",
"music.ringTone|block": "ring tone (Hz)|%note=device_note",
@ -251,6 +324,9 @@
"pins.servoWritePin|block": "servo write|pin %name|to %value",
"pins.setEvents|block": "set pin %pin|to emit %type|events",
"pins.setPull|block": "set pull|pin %pin|to %pull",
"pins.spiFormat|block": "spi format|bits %bits|mode %mode",
"pins.spiFrequency|block": "spi frequency %frequency",
"pins.spiPins|block": "spi set pins|MOSI %mosi|MISO %miso|SCK %sck",
"pins.spiWrite|block": "spi write %value",
"pins|block": "pins",
"serial.delimiters|block": "%del",

View File

@ -6,7 +6,7 @@
*/
//% color=#54C9C9 weight=100 icon="\uf00a"
namespace basic {
/**
/**
* Sets the color on the build-in LED. Set to 0 to turn off.
*/
//% blockId=device_set_led_color block="set led to %color=color_id"
@ -34,10 +34,9 @@ namespace basic {
//% blockId=device_show_number block="show|number %number" blockGap=8
//% async
//% parts="ledmatrix"
void showNumber(int value, int interval = 150) {
if (interval < 0)
return;
void showNumber(int value, int interval = 150) {
if (interval <= 0)
interval = 1;
ManagedString t(value);
if (value < 0 || value >= 10) {
uBit.display.scroll(t, interval);
@ -51,11 +50,11 @@ namespace basic {
* @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing
*/
//% help=basic/show-leds
//% help=basic/show-leds
//% weight=95 blockGap=8
//% imageLiteral=1 async
//% blockId=device_show_leds
//% block="show leds"
//% block="show leds" icon="\uf00a"
//% parts="ledmatrix"
void showLeds(ImageLiteral leds, int interval = 400) {
uBit.display.print(MicroBitImage(imageBytes(leds)), 0, 0, 0, interval);
@ -66,15 +65,15 @@ namespace basic {
* @param text the text to scroll on the screen, eg: "Hello!"
* @param interval how fast to shift characters; eg: 150, 100, 200, -100
*/
//% help=basic/show-string
//% help=basic/show-string
//% weight=87 blockGap=8
//% block="show|string %text"
//% block="show|string %text"
//% async
//% blockId=device_print_message
//% parts="ledmatrix"
void showString(StringData *text, int interval = 150) {
if (interval < 0)
return;
if (interval <= 0)
interval = 1;
ManagedString s(text);
int l = s.length();
if (l == 0) {
@ -93,6 +92,7 @@ namespace basic {
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix"
//% advanced=true
void clearScreen() {
uBit.display.image.clear();
}
@ -105,7 +105,7 @@ namespace basic {
//% help=basic/show-animation imageLiteral=1 async
//% parts="ledmatrix"
void showAnimation(ImageLiteral leds, int interval = 400) {
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0);
uBit.display.animate(MicroBitImage(imageBytes(leds)), interval, 5, 0, 0);
}
/**
@ -130,8 +130,8 @@ namespace basic {
* 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=8
//% blockId=device_forever block="forever"
//% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
//% blockId=device_forever block="forever" icon="\uf01e"
void forever(Action a) {
if (a != 0) {
incr(a);
@ -145,7 +145,7 @@ namespace basic {
*/
//% help=basic/pause weight=54
//% async block="pause (ms) %pause"
//% blockId=device_pause
//% blockId=device_pause icon="\uf110"
void pause(int ms) {
fiber_sleep(ms);
}

View File

@ -20,97 +20,190 @@ enum class EventCreationMode {
// TODO shouldn't these be renamed to something more sensible anyways?
enum EventBusSource {
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_A_ = MICROBIT_ID_BUTTON_A,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_B_ = MICROBIT_ID_BUTTON_B,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_AB_ = MICROBIT_ID_BUTTON_AB,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_RADIO_ = MICROBIT_ID_RADIO,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_GESTURE_ = MICROBIT_ID_GESTURE,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_ACCELEROMETER_ = MICROBIT_ID_ACCELEROMETER,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P0_ = MICROBIT_ID_IO_P0,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P1_ = MICROBIT_ID_IO_P1,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P2_ = MICROBIT_ID_IO_P2,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P3_ = MICROBIT_ID_IO_P3,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P4_ = MICROBIT_ID_IO_P4,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P5_ = MICROBIT_ID_IO_P5,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P6_ = MICROBIT_ID_IO_P6,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P7_ = MICROBIT_ID_IO_P7,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P8_ = MICROBIT_ID_IO_P8,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P9_ = MICROBIT_ID_IO_P9,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P10_ = MICROBIT_ID_IO_P10,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P11_ = MICROBIT_ID_IO_P11,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P12_ = MICROBIT_ID_IO_P12,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P13_ = MICROBIT_ID_IO_P13,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P14_ = MICROBIT_ID_IO_P14,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P15_ = MICROBIT_ID_IO_P15,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P16_ = MICROBIT_ID_IO_P16,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P19_ = MICROBIT_ID_IO_P19,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P20_ = MICROBIT_ID_IO_P20,
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P21_ = MICROBIT_ID_IO_P21,
//% blockIdentity="control.eventSourceId"
MES_DEVICE_INFO_ID_ = MES_DEVICE_INFO_ID,
//% blockIdentity="control.eventSourceId"
MES_SIGNAL_STRENGTH_ID_ = MES_SIGNAL_STRENGTH_ID,
//% blockIdentity="control.eventSourceId"
MES_DPAD_CONTROLLER_ID_ = MES_DPAD_CONTROLLER_ID,
//% blockIdentity="control.eventSourceId"
MES_BROADCAST_GENERAL_ID_ = MES_BROADCAST_GENERAL_ID,
};
enum EventBusValue {
//% blockIdentity="control.eventValueId"
MICROBIT_EVT_ANY_ = MICROBIT_EVT_ANY,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_DOWN_ = MICROBIT_BUTTON_EVT_DOWN,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_UP_ = MICROBIT_BUTTON_EVT_UP,
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_CLICK_ = MICROBIT_BUTTON_EVT_CLICK,
//% blockIdentity="control.eventValueId"
MICROBIT_RADIO_EVT_DATAGRAM_ = MICROBIT_RADIO_EVT_DATAGRAM,
//% blockIdentity="control.eventValueId"
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE_ = MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_RISE_ = MICROBIT_PIN_EVT_RISE,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_FALL_ = MICROBIT_PIN_EVT_FALL,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_HI_ = MICROBIT_PIN_EVT_PULSE_HI,
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_LO_ = MICROBIT_PIN_EVT_PULSE_LO,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM1_ = MES_ALERT_EVT_ALARM1,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM2_ = MES_ALERT_EVT_ALARM2,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM3_ = MES_ALERT_EVT_ALARM3,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM4_ = MES_ALERT_EVT_ALARM4,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM5_ = MES_ALERT_EVT_ALARM5,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM6_ = MES_ALERT_EVT_ALARM6,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_DISPLAY_TOAST_ = MES_ALERT_EVT_DISPLAY_TOAST,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_FIND_MY_PHONE_ = MES_ALERT_EVT_FIND_MY_PHONE,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_RINGTONE_ = MES_ALERT_EVT_PLAY_RINGTONE,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_SOUND_ = MES_ALERT_EVT_PLAY_SOUND,
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_VIBRATE_ = MES_ALERT_EVT_VIBRATE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE_ = MES_CAMERA_EVT_LAUNCH_PHOTO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE_ = MES_CAMERA_EVT_LAUNCH_VIDEO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_START_VIDEO_CAPTURE_ = MES_CAMERA_EVT_START_VIDEO_CAPTURE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_PHOTO_MODE_ = MES_CAMERA_EVT_STOP_PHOTO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE_ = MES_CAMERA_EVT_STOP_VIDEO_CAPTURE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_MODE_ = MES_CAMERA_EVT_STOP_VIDEO_MODE,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TAKE_PHOTO_ = MES_CAMERA_EVT_TAKE_PHOTO,
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TOGGLE_FRONT_REAR_ = MES_CAMERA_EVT_TOGGLE_FRONT_REAR,
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_OFF_ = MES_DEVICE_DISPLAY_OFF,
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_ON_ = MES_DEVICE_DISPLAY_ON,
//% blockIdentity="control.eventValueId"
MES_DEVICE_GESTURE_DEVICE_SHAKEN_ = MES_DEVICE_GESTURE_DEVICE_SHAKEN,
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_CALL_ = MES_DEVICE_INCOMING_CALL,
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_MESSAGE_ = MES_DEVICE_INCOMING_MESSAGE,
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_LANDSCAPE_ = MES_DEVICE_ORIENTATION_LANDSCAPE,
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_PORTRAIT_ = MES_DEVICE_ORIENTATION_PORTRAIT,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_DOWN_ = MES_DPAD_BUTTON_1_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_UP_ = MES_DPAD_BUTTON_1_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_DOWN_ = MES_DPAD_BUTTON_2_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_UP_ = MES_DPAD_BUTTON_2_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_DOWN_ = MES_DPAD_BUTTON_3_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_UP_ = MES_DPAD_BUTTON_3_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_DOWN_ = MES_DPAD_BUTTON_4_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_UP_ = MES_DPAD_BUTTON_4_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_DOWN_ = MES_DPAD_BUTTON_A_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_UP_ = MES_DPAD_BUTTON_A_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_DOWN_ = MES_DPAD_BUTTON_B_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_UP_ = MES_DPAD_BUTTON_B_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_DOWN_ = MES_DPAD_BUTTON_C_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_UP_ = MES_DPAD_BUTTON_C_UP,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_DOWN_ = MES_DPAD_BUTTON_D_DOWN,
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_UP_ = MES_DPAD_BUTTON_D_UP,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_FORWARD_ = MES_REMOTE_CONTROL_EVT_FORWARD,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_NEXTTRACK_ = MES_REMOTE_CONTROL_EVT_NEXTTRACK,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PAUSE_ = MES_REMOTE_CONTROL_EVT_PAUSE,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PLAY_ = MES_REMOTE_CONTROL_EVT_PLAY,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PREVTRACK_ = MES_REMOTE_CONTROL_EVT_PREVTRACK,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_REWIND_ = MES_REMOTE_CONTROL_EVT_REWIND,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_STOP_ = MES_REMOTE_CONTROL_EVT_STOP,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN_ = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN,
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP,
};
@ -126,7 +219,7 @@ namespace control {
/**
* Schedules code that run in the background.
*/
//% help=control/in-background
//% help=control/in-background blockAllowMultiple=1 afterOnStart=true
//% blockId="control_in_background" block="run in background" blockGap=8
void inBackground(Action a) {
runInBackground(a);
@ -158,6 +251,7 @@ namespace control {
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
*/
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
//% help=control/raise-event
//% mode.defl=CREATE_AND_FIRE
void raiseEvent(int src, int value, EventCreationMode mode) {
MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
@ -167,6 +261,7 @@ namespace control {
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler);
@ -176,6 +271,7 @@ namespace control {
* Gets the value of the last event executed on the bus
*/
//% blockId=control_event_value" block="event value"
//% help=control/event-value
//% weight=18
int eventValue() {
return pxt::lastEvent.value;
@ -185,6 +281,7 @@ namespace control {
* Gets the timestamp of the last event executed on the bus
*/
//% blockId=control_event_timestamp" block="event timestamp"
//% help=control/event-timestamp
//% weight=19 blockGap=8
int eventTimestamp() {
return pxt::lastEvent.timestamp;
@ -194,6 +291,7 @@ namespace control {
* Gets a friendly name for the device derived from the its serial number
*/
//% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% advanced=true
StringData* deviceName() {
return ManagedString(microbit_friendly_name()).leakData();
}
@ -202,6 +300,7 @@ namespace control {
* Derive a unique, consistent serial number of this device from internal data.
*/
//% blockId="control_device_serial_number" block="device serial number" weight=9
//% advanced=true
int deviceSerialNumber() {
return microbit_serial_number();
}

View File

@ -4,46 +4,47 @@
//% weight=1 color="#42495F" icon="\uf233"
//% advanced=true
namespace control {
/**
* Returns the value of a C++ runtime constant
*/
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% shim=TD_ID
export function eventSourceId(id: EventBusSource): number {
return id;
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID
export function eventValueId(id: EventBusValue): number {
return id;
}
/**
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code: number) { }
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
export function assert(condition: boolean, msg ?: string) {
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null) {
console.log(msg)
}
panic(98)
/**
* Returns the value of a C++ runtime constant
*/
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% shim=TD_ID advanced=true
export function eventSourceId(id: EventBusSource): number {
return id;
}
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID advanced=true
export function eventValueId(id: EventBusValue): number {
return id;
}
/**
* Display specified error code and stop the program.
*/
//% shim=pxtrt::panic
export function panic(code: number) { }
/**
* If the condition is false, display msg on serial console, and panic with code 098.
*/
export function assert(condition: boolean, msg?: string) {
if (!condition) {
console.log("ASSERTION FAILED")
if (msg != null) {
console.log(msg)
}
panic(98)
}
}
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
export function runtimeWarning(message: string) { }
}
/**
* Display warning in the simulator.
*/
//% shim=pxtrt::runtimeWarning
export function runtimeWarning(message: string) { }
}

View File

@ -29,6 +29,15 @@ namespace String_ {
return 0;
}
//%
int compareDecr(StringData *s, StringData *that) {
int r = compare(s, that);
if (r == 0)
decr((uint32_t)that);
return r;
}
//%
int length(StringData *s) { return s->len; }
@ -112,6 +121,15 @@ namespace Number_ {
int div(int x, int y) { return x / y; }
//%
int mod(int x, int y) { return x % y; }
//%
bool eqDecr(int x, int y) {
if(x == y) {
decr(y);
return true;
}
return false;
}
}
namespace Math_ {
@ -220,17 +238,12 @@ namespace pxt {
return bytecode[17] * 2;
}
#ifndef PAGE_SIZE
#define PAGE_SIZE 1
#endif
//%
uint32_t afterProgramPage() {
uint32_t ptr = (uint32_t)&bytecode[0];
ptr += programSize();
ptr = (ptr + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
if (ptr % PAGE_SIZE != 0)
ptr = (ptr & ~(PAGE_SIZE-1)) + PAGE_SIZE;
return ptr;
}
}

134
libs/core/enums.d.ts vendored
View File

@ -116,6 +116,47 @@ declare namespace basic {
*/
//% block="6g"
SixG = 10, // MICROBIT_ACCELEROMETER_EVT_6G
/**
* Raised when a 8G shock is detected
*/
//% block="8g"
EightG = 11, // MICROBIT_ACCELEROMETER_EVT_8G
}
declare const enum MesDpadButtonInfo {
//% block="A down"
ADown = 1, // MES_DPAD_BUTTON_A_DOWN
//% block="A up"
AUp = 2, // MES_DPAD_BUTTON_A_UP
//% block="B down"
BDown = 3, // MES_DPAD_BUTTON_B_DOWN
//% block="B up"
BUp = 4, // MES_DPAD_BUTTON_B_UP
//% block="C down"
CDown = 5, // MES_DPAD_BUTTON_C_DOWN
//% block="C up"
CUp = 6, // MES_DPAD_BUTTON_C_UP
//% block="D down"
DDown = 7, // MES_DPAD_BUTTON_D_DOWN
//% block="D up"
DUp = 8, // MES_DPAD_BUTTON_D_UP
//% block="1 down"
_1Down = 9, // MES_DPAD_BUTTON_1_DOWN
//% block="1 up"
_1Up = 10, // MES_DPAD_BUTTON_1_UP
//% block="2 down"
_2Down = 11, // MES_DPAD_BUTTON_2_DOWN
//% block="2 up"
_2Up = 12, // MES_DPAD_BUTTON_2_UP
//% block="3 down"
_3Down = 13, // MES_DPAD_BUTTON_3_DOWN
//% block="3 up"
_3Up = 14, // MES_DPAD_BUTTON_3_UP
//% block="4 down"
_4Down = 15, // MES_DPAD_BUTTON_4_DOWN
//% block="4 up"
_4Up = 16, // MES_DPAD_BUTTON_4_UP
}
declare namespace input {
}
@ -138,98 +179,191 @@ declare namespace input {
declare const enum EventBusSource {
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_A = 1, // MICROBIT_ID_BUTTON_A
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_B = 2, // MICROBIT_ID_BUTTON_B
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_BUTTON_AB = 26, // MICROBIT_ID_BUTTON_AB
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_RADIO = 29, // MICROBIT_ID_RADIO
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_GESTURE = 27, // MICROBIT_ID_GESTURE
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_ACCELEROMETER = 4, // MICROBIT_ID_ACCELEROMETER
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P0 = 7, // MICROBIT_ID_IO_P0
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P1 = 8, // MICROBIT_ID_IO_P1
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P2 = 9, // MICROBIT_ID_IO_P2
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P3 = 10, // MICROBIT_ID_IO_P3
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P4 = 11, // MICROBIT_ID_IO_P4
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P5 = 12, // MICROBIT_ID_IO_P5
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P6 = 13, // MICROBIT_ID_IO_P6
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P7 = 14, // MICROBIT_ID_IO_P7
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P8 = 15, // MICROBIT_ID_IO_P8
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P9 = 16, // MICROBIT_ID_IO_P9
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P10 = 17, // MICROBIT_ID_IO_P10
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P11 = 18, // MICROBIT_ID_IO_P11
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P12 = 19, // MICROBIT_ID_IO_P12
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P13 = 20, // MICROBIT_ID_IO_P13
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P14 = 21, // MICROBIT_ID_IO_P14
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P15 = 22, // MICROBIT_ID_IO_P15
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P16 = 23, // MICROBIT_ID_IO_P16
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P19 = 24, // MICROBIT_ID_IO_P19
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P20 = 25, // MICROBIT_ID_IO_P20
//% blockIdentity="control.eventSourceId"
MICROBIT_ID_IO_P21 = 50, // MICROBIT_ID_IO_P21
//% blockIdentity="control.eventSourceId"
MES_DEVICE_INFO_ID = 1103, // MES_DEVICE_INFO_ID
//% blockIdentity="control.eventSourceId"
MES_SIGNAL_STRENGTH_ID = 1101, // MES_SIGNAL_STRENGTH_ID
//% blockIdentity="control.eventSourceId"
MES_DPAD_CONTROLLER_ID = 1104, // MES_DPAD_CONTROLLER_ID
//% blockIdentity="control.eventSourceId"
MES_BROADCAST_GENERAL_ID = 2000, // MES_BROADCAST_GENERAL_ID
}
declare const enum EventBusValue {
//% blockIdentity="control.eventValueId"
MICROBIT_EVT_ANY = 0, // MICROBIT_EVT_ANY
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_DOWN = 1, // MICROBIT_BUTTON_EVT_DOWN
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_UP = 2, // MICROBIT_BUTTON_EVT_UP
//% blockIdentity="control.eventValueId"
MICROBIT_BUTTON_EVT_CLICK = 3, // MICROBIT_BUTTON_EVT_CLICK
//% blockIdentity="control.eventValueId"
MICROBIT_RADIO_EVT_DATAGRAM = 1, // MICROBIT_RADIO_EVT_DATAGRAM
//% blockIdentity="control.eventValueId"
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1, // MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_RISE = 2, // MICROBIT_PIN_EVT_RISE
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_FALL = 3, // MICROBIT_PIN_EVT_FALL
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_HI = 4, // MICROBIT_PIN_EVT_PULSE_HI
//% blockIdentity="control.eventValueId"
MICROBIT_PIN_EVT_PULSE_LO = 5, // MICROBIT_PIN_EVT_PULSE_LO
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM1 = 6, // MES_ALERT_EVT_ALARM1
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM2 = 7, // MES_ALERT_EVT_ALARM2
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM3 = 8, // MES_ALERT_EVT_ALARM3
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM4 = 9, // MES_ALERT_EVT_ALARM4
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM5 = 10, // MES_ALERT_EVT_ALARM5
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_ALARM6 = 11, // MES_ALERT_EVT_ALARM6
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_DISPLAY_TOAST = 1, // MES_ALERT_EVT_DISPLAY_TOAST
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_FIND_MY_PHONE = 5, // MES_ALERT_EVT_FIND_MY_PHONE
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_RINGTONE = 4, // MES_ALERT_EVT_PLAY_RINGTONE
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_PLAY_SOUND = 3, // MES_ALERT_EVT_PLAY_SOUND
//% blockIdentity="control.eventValueId"
MES_ALERT_EVT_VIBRATE = 2, // MES_ALERT_EVT_VIBRATE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE = 1, // MES_CAMERA_EVT_LAUNCH_PHOTO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE = 2, // MES_CAMERA_EVT_LAUNCH_VIDEO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_START_VIDEO_CAPTURE = 4, // MES_CAMERA_EVT_START_VIDEO_CAPTURE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_PHOTO_MODE = 6, // MES_CAMERA_EVT_STOP_PHOTO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE = 5, // MES_CAMERA_EVT_STOP_VIDEO_CAPTURE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_STOP_VIDEO_MODE = 7, // MES_CAMERA_EVT_STOP_VIDEO_MODE
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TAKE_PHOTO = 3, // MES_CAMERA_EVT_TAKE_PHOTO
//% blockIdentity="control.eventValueId"
MES_CAMERA_EVT_TOGGLE_FRONT_REAR = 8, // MES_CAMERA_EVT_TOGGLE_FRONT_REAR
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_OFF = 5, // MES_DEVICE_DISPLAY_OFF
//% blockIdentity="control.eventValueId"
MES_DEVICE_DISPLAY_ON = 6, // MES_DEVICE_DISPLAY_ON
//% blockIdentity="control.eventValueId"
MES_DEVICE_GESTURE_DEVICE_SHAKEN = 4, // MES_DEVICE_GESTURE_DEVICE_SHAKEN
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_CALL = 7, // MES_DEVICE_INCOMING_CALL
//% blockIdentity="control.eventValueId"
MES_DEVICE_INCOMING_MESSAGE = 8, // MES_DEVICE_INCOMING_MESSAGE
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_LANDSCAPE = 1, // MES_DEVICE_ORIENTATION_LANDSCAPE
//% blockIdentity="control.eventValueId"
MES_DEVICE_ORIENTATION_PORTRAIT = 2, // MES_DEVICE_ORIENTATION_PORTRAIT
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_DOWN = 9, // MES_DPAD_BUTTON_1_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_1_UP = 10, // MES_DPAD_BUTTON_1_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_DOWN = 11, // MES_DPAD_BUTTON_2_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_2_UP = 12, // MES_DPAD_BUTTON_2_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_DOWN = 13, // MES_DPAD_BUTTON_3_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_3_UP = 14, // MES_DPAD_BUTTON_3_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_DOWN = 15, // MES_DPAD_BUTTON_4_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_4_UP = 16, // MES_DPAD_BUTTON_4_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_DOWN = 1, // MES_DPAD_BUTTON_A_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_A_UP = 2, // MES_DPAD_BUTTON_A_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_DOWN = 3, // MES_DPAD_BUTTON_B_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_B_UP = 4, // MES_DPAD_BUTTON_B_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_DOWN = 5, // MES_DPAD_BUTTON_C_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_C_UP = 6, // MES_DPAD_BUTTON_C_UP
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_DOWN = 7, // MES_DPAD_BUTTON_D_DOWN
//% blockIdentity="control.eventValueId"
MES_DPAD_BUTTON_D_UP = 8, // MES_DPAD_BUTTON_D_UP
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_FORWARD = 6, // MES_REMOTE_CONTROL_EVT_FORWARD
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_NEXTTRACK = 4, // MES_REMOTE_CONTROL_EVT_NEXTTRACK
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PAUSE = 2, // MES_REMOTE_CONTROL_EVT_PAUSE
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PLAY = 1, // MES_REMOTE_CONTROL_EVT_PLAY
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_PREVTRACK = 5, // MES_REMOTE_CONTROL_EVT_PREVTRACK
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_REWIND = 7, // MES_REMOTE_CONTROL_EVT_REWIND
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_STOP = 3, // MES_REMOTE_CONTROL_EVT_STOP
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN = 9, // MES_REMOTE_CONTROL_EVT_VOLUMEDOWN
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP
}
declare namespace control {

View File

@ -32,22 +32,22 @@ namespace game {
let _countdownPause: number = 0;
let _level: number = 1;
let _gameId: number = 0;
let img: Image;
let sprites: LedSprite[];
let _img: Image;
let _sprites: LedSprite[];
let _paused: boolean = false;
let _backgroundAnimation = false; // indicates if an auxiliary animation (and fiber) is already running
/**
* Creates a new LED sprite pointing to the right.
* @param x sprite horizontal coordinate, eg: 2
* @param y sprite vertical coordinate, eg: 2
*/
//% weight=60
//% weight=60 blockGap=8 help=game/create-sprite
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
//% parts="ledmatrix"
export function createSprite(x: number, y: number): LedSprite {
init();
let p = new LedSprite(x, y);
sprites.push(p);
plot();
return p;
}
@ -61,7 +61,7 @@ namespace game {
}
/**
* Adds points to the current score
* Adds points to the current score and shows an animation
* @param points amount of points to change, eg: 1
*/
//% weight=10 help=game/add-score
@ -69,18 +69,22 @@ namespace game {
//% parts="ledmatrix"
export function addScore(points: number): void {
setScore(_score + points);
control.inBackground(() => {
led.stopAnimation();
basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20);
});
if (!_paused && !_backgroundAnimation) {
_backgroundAnimation = true;
control.inBackground(() => {
led.stopAnimation();
basic.showAnimation(`0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0`, 20);
_backgroundAnimation = false;
});
}
}
/**
* Starts a game countdown timer
* Shows an animation, then starts a game countdown timer, which causes Game Over when it reaches 0
* @param ms countdown duration in milliseconds, eg: 10000
*/
//% weight=9 help=game/start-countdown
@ -96,6 +100,7 @@ namespace game {
_countdownPause = Math.max(500, ms);
_startTime = -1;
_endTime = input.runningTime() + _countdownPause;
_paused = false;
control.inBackground(() => {
basic.pause(_countdownPause);
gameOver();
@ -104,7 +109,7 @@ namespace game {
}
/**
* Displays a game over animation.
* Displays a game over animation and the score.
*/
//% weight=8 help=game/game-over
//% blockId=game_game_over block="game over"
@ -115,7 +120,6 @@ namespace game {
unplugEvents();
led.stopAnimation();
led.setBrightness(255);
led.setDisplayMode(DisplayMode.BackAndWhite);
while (true) {
for (let i = 0; i < 8; i++) {
basic.clearScreen();
@ -146,8 +150,9 @@ namespace game {
/**
* Sets the current score value
* @param value TODO
* @param value new score value.
*/
//% blockId=game_set_score block="set score %points" blockGap=8
//% weight=10 help=game/set-score
export function setScore(value: number): void {
_score = Math.max(0, value);
@ -202,14 +207,15 @@ namespace game {
//% parts="ledmatrix"
export function removeLife(life: number): void {
setLife(_life - life);
control.inBackground(() => {
led.stopAnimation();
basic.showAnimation(`1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0
if (!_paused)
control.inBackground(() => {
led.stopAnimation();
basic.showAnimation(`1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0`, 40);
});
});
}
/**
@ -264,10 +270,38 @@ namespace game {
* Indicates if the game is display the game over sequence.
*/
export function isGameOver(): boolean {
let over: boolean;
return _isGameOver;
}
/**
* Indicates if the game rendering is paused to allow other animations
*/
//%
export function isPaused(): boolean {
return _paused;
}
/**
* Pauses the game rendering engine to allow other animations
*/
//% blockId=game_pause block="pause"
//% advanced=true blockGap=8 help=game/pause
export function pause(): void {
plot()
_paused = true;
}
/**
* Resumes the game rendering engine
*/
//% blockId=game_resume block="resume"
//% advanced=true blockGap=8 help=game/resumeP
export function resume(): void {
_paused = false;
plot();
}
/**
* returns false if game can't start
*/
@ -287,29 +321,35 @@ namespace game {
});
}
/**
* A game sprite rendered as a single LED
*/
//%
export class LedSprite {
private _x: number;
private _y: number;
private _dir: number;
private _brightness: number;
private _blink: number;
private _enabled: boolean;
constructor(x: number, y: number) {
this._x = Math.clamp(0, 4, x);
this._y = Math.clamp(0, 4, y);
this._dir = 90;
this._brightness = 255;
this._enabled = true;
init();
sprites.push(this);
_sprites.push(this);
plot();
}
/**
* Move a certain number of LEDs
* Move a certain number of LEDs in the current direction
* @param this the sprite to move
* @param leds number of leds to move, eg: 1, -1
*/
//% weight=50
//% weight=50 help=game/move
//% blockId=game_move_sprite block="%sprite|move by %leds" blockGap=8
//% parts="ledmatrix"
public move(leds: number): void {
@ -355,10 +395,10 @@ namespace game {
}
/**
* If touching the edge of the stage, then bounce away.
* If touching the edge of the stage and facing towards it, then turn away.
* @param this TODO
*/
//% weight=18
//% weight=18 help=game/if-on-edge-bounce
//% blockId=game_sprite_bounce block="%sprite|if on edge, bounce"
//% parts="ledmatrix"
public ifOnEdgeBounce(): void {
@ -412,7 +452,7 @@ namespace game {
* @param direction left or right
* @param degrees angle in degrees to turn, eg: 45, 90, 180, 135
*/
//% weight=49
//% weight=49 help=game/turn
//% blockId=game_turn_sprite block="%sprite|turn %direction|by (°) %degrees"
public turn(direction: Direction, degrees: number) {
if (direction == Direction.Right)
@ -444,7 +484,7 @@ namespace game {
* @param property the name of the property to change
* @param the updated value
*/
//% weight=29
//% weight=29 help=game/set
//% blockId=game_sprite_set_property block="%sprite|set %property|to %value" blockGap=8
public set(property: LedSpriteProperty, value: number) {
switch (property) {
@ -461,7 +501,7 @@ namespace game {
* @param property the name of the property to change
* @param value amount of change, eg: 1
*/
//% weight=30
//% weight=30 help=game/change
//% blockId=game_sprite_change_xy block="%sprite|change %property|by %value" blockGap=8
public change(property: LedSpriteProperty, value: number) {
switch (property) {
@ -477,7 +517,7 @@ namespace game {
* Gets a property of the sprite
* @param property the name of the property to change
*/
//% weight=28
//% weight=28 help=game/get
//% blockId=game_sprite_property block="%sprite|%property"
public get(property: LedSpriteProperty) {
switch (property) {
@ -567,21 +607,21 @@ namespace game {
}
/**
* Reports true if sprite is touching specified sprite
* Reports true if sprite has the same position as specified sprite
* @param this TODO
* @param other TODO
*/
//% weight=20
//% weight=20 help=game/is-touching
//% blockId=game_sprite_touching_sprite block="%sprite|touching %other|?" blockGap=8
public isTouching(other: LedSprite): boolean {
return this._x == other._x && this._y == other._y;
return this._enabled && other._enabled && this._x == other._x && this._y == other._y;
}
/**
* Reports true if sprite is touching an edge
* @param this TODO
*/
//% weight=19
//% weight=19 help=game/is-touching-edge
//% blockId=game_sprite_touching_edge block="%sprite|touching edge?" blockGap=8
public isTouchingEdge(): boolean {
return this._x == 0 || this._x == 4 || this._y == 0 || this._y == 4;
@ -589,7 +629,7 @@ namespace game {
/**
* Turns on the sprite (on by default)
* @param this TODO
* @param this the sprite
*/
public on(): void {
this.setBrightness(255);
@ -597,7 +637,7 @@ namespace game {
/**
* Turns off the sprite (on by default)
* @param this TODO
* @param this the sprite
*/
public off(): void {
this.setBrightness(0);
@ -605,8 +645,8 @@ namespace game {
/**
* Set the ``brightness`` of a sprite
* @param this TODO
* @param brightness TODO
* @param this the sprite
* @param brightness the brightness from 0 (off) to 255 (on), eg: 255.
*/
//% parts="ledmatrix"
public setBrightness(brightness: number): void {
@ -616,8 +656,9 @@ namespace game {
/**
* Reports the ``brightness` of a sprite on the LED screen
* @param this TODO
* @param this the sprite
*/
//% parts="ledmatrix"
public brightness(): number {
let r: number;
return this._brightness;
@ -625,8 +666,8 @@ namespace game {
/**
* Changes the ``y`` position by the given amount
* @param this TODO
* @param value TODO
* @param this the sprite
* @param value the value to change brightness
*/
public changeBrightnessBy(value: number): void {
this.setBrightness(this._brightness + value);
@ -642,11 +683,15 @@ namespace game {
}
/**
* Deletes the sprite from the game engine. All further operation of the sprite will not have any effect.
* @param sprite TODO
* Deletes the sprite from the game engine. The sprite will no longer appear on the screen or interact with other sprites.
* @param this sprite to delete
*/
public delete(sprite: LedSprite): void {
sprites.removeElement(sprite);
//% weight=59 help=game/delete
//% blockId="game_delete_sprite" block="delete %this"
public delete(): void {
this._enabled = false;
if (_sprites.removeElement(this))
plot();
}
/**
@ -686,30 +731,29 @@ namespace game {
r = (now / ps._blink) % 2;
}
if (r == 0) {
img.setPixelBrightness(ps._x, ps._y, img.pixelBrightness(ps._x, ps._y) + ps._brightness);
_img.setPixelBrightness(ps._x, ps._y, _img.pixelBrightness(ps._x, ps._y) + ps._brightness);
}
}
}
}
function init(): void {
if (img == null) {
img = images.createImage(
`0 0 0 0 0
if (_img) return;
const img = images.createImage(
`0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0`);
sprites = (<LedSprite[]>[]);
led.setDisplayMode(DisplayMode.Greyscale);
basic.forever(() => {
basic.pause(30);
plot();
if (game.isGameOver()) {
basic.pause(600);
}
});
}
_sprites = (<LedSprite[]>[]);
basic.forever(() => {
basic.pause(30);
plot();
if (game.isGameOver()) {
basic.pause(600);
}
});
_img = img;
}
/**
@ -717,15 +761,23 @@ namespace game {
*/
//% parts="ledmatrix"
function plot(): void {
if (game.isGameOver()) {
if (game.isGameOver() || game.isPaused() || !_img || _backgroundAnimation) {
return;
}
let now = input.runningTime();
img.clear();
for (let i = 0; i < sprites.length; i++) {
sprites[i]._plot(now);
// ensure greyscale mode
const dm = led.displayMode();
if (dm != DisplayMode.Greyscale)
led.setDisplayMode(DisplayMode.Greyscale);
// render sprites
const now = input.runningTime();
_img.clear();
for (let i = 0; i < _sprites.length; i++) {
_sprites[i]._plot(now);
}
img.plotImage(0);
_img.plotImage(0);
// restore previous display mode
if (dm != DisplayMode.Greyscale)
led.setDisplayMode(dm);
}
/**
@ -737,4 +789,3 @@ namespace game {
}
}

View File

@ -27,103 +27,143 @@ THE SOFTWARE.
enum IconNames {
//% block="heart"
//% blockImage=1
Heart = 0,
//% block="small heart"
//% blockImage=1
SmallHeart,
//% block="yes"
//% blockImage=1
Yes,
//% block="no"
//% blockImage=1
No,
//% block="happy"
//% blockImage=1
Happy,
//% block="sad"
//% blockImage=1
Sad,
//% block="confused"
//% blockImage=1
Confused,
//% block="angry"
//% blockImage=1
Angry,
//% block="asleep"
//% blockImage=1
Asleep,
//% block="surprised"
//% blockImage=1
Surprised,
//% block="silly"
//% blockImage=1
Silly,
//% block="fabulous"
//% blockImage=1
Fabulous,
//% block="meh"
//% blockImage=1
Meh,
//% block="t-shirt"
//% blockImage=1
TShirt,
//% block="roller skate"
//% blockImage=1
Rollerskate,
//% block="duck"
//% blockImage=1
Duck,
//% block="house"
//% blockImage=1
House,
//% block="tortoise"
//% blockImage=1
Tortoise,
//% block="butterfly"
//% blockImage=1
Butterfly,
//% block="stick figure"
//% blockImage=1
StickFigure,
//% block="ghost"
//% blockImage=1
Ghost,
//% block="sword"
//% blockImage=1
Sword,
//% block="giraffe"
//% blockImage=1
Giraffe,
//% block="skull"
//% blockImage=1
Skull,
//% block="umbrella"
//% blockImage=1
Umbrella,
//% block="snake"
//% blockImage=1
Snake,
//% block="rabbit"
//% blockImage=1
Rabbit,
//% block="cow"
//% blockImage=1
Cow,
//% block="quarter note"
//% blockImage=1
QuarterNote,
//% block="eigth note"
//% blockImage=1
EigthNote,
//% block="pitchfork"
//% blockImage=1
Pitchfork,
//% block="pac man"
Pacman,
//% block="target"
//% blockImage=1
Target,
//% block="triangle"
//% blockImage=1
Triangle,
//% block="left triangle"
//% blockImage=1
LeftTriangle,
//% block="chess board"
//% blockImage=1
Chessboard,
//% block="diamond"
//% blockImage=1
Diamond,
//% block="small diamond"
//% blockImage=1
SmallDiamond,
//% block="square"
//% blockImage=1
Square,
//% block="small square"
SmallSquare,
//% blockImage=1
SmallSquare,
//% block="scissors"
//% blockImage=1
Scissors
}
enum ArrowNames {
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="North"
North = 0,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="North East"
NorthEast,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="East"
East,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="South East"
SouthEast,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="South"
South,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="South West"
SouthWest,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="West"
West,
//% blockIdentity=images.arrowNumber
//% blockIdentity=images.arrowNumber block="North West"
NorthWest,
}
@ -131,393 +171,376 @@ namespace basic {
/**
* Draws the selected icon on the LED screen
* @param icon the predifined icon id
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
//% weight=90 blockGap=8
//% blockId=basic_show_icon
//% blockId=basic_show_icon
//% block="show icon %i" icon="\uf00a"
//% parts="ledmatrix"
//% help=basic/show-icon
export function showIcon(icon: IconNames) {
//% i.fieldEditor="gridpicker"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
//% i.fieldOptions.itemColour="black" i.fieldOptions.tooltips="true"
export function showIcon(icon: IconNames, interval = 600) {
let res = images.iconImage(icon)
res.showImage(0)
res.showImage(0, interval)
}
/**
* Shows an arrow on screent
* @param direction the direction of the arrow
* @param interval the amount of time (milliseconds) to show the icon. Default is 600.
*/
//% weight=50 blockGap=8
//% blockId=basic_show_arrow
//% blockId=basic_show_arrow
//% block="show arrow %i=device_arrow"
//% parts="ledmatrix"
//% advanced=true
//% help=basic/show-arrow
export function showArrow(i: number) {
let res = images.arrowImage(i)
res.showImage(0)
export function showArrow(direction: number, interval = 600) {
let res = images.arrowImage(direction)
res.showImage(0, interval)
}
}
namespace images {
function getArrow(i : ArrowNames): string {
switch(i) {
//% weight=50 blockGap=8
//% help=images/arrow-image
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i: ArrowNames): Image {
switch (i) {
// compass directions
case ArrowNames.North: return `
case ArrowNames.North: return images.createImage(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .`;
case ArrowNames.NorthEast: return `
. . # . .`);
case ArrowNames.NorthEast: return images.createImage(`
. . # # #
. . . # #
. . # . #
. # . . .
# . . . .`;
case ArrowNames.East: return `
# . . . .`);
case ArrowNames.East: return images.createImage(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .`;
case ArrowNames.SouthEast: return `
. . # . .`);
case ArrowNames.SouthEast: return images.createImage(`
# . . . .
. # . . .
. . # . #
. . . # #
. . # # #`;
case ArrowNames.South: return `
. . # # #`);
case ArrowNames.South: return images.createImage(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .`;
case ArrowNames.SouthWest: return `
. . # . .`);
case ArrowNames.SouthWest: return images.createImage(`
. . . . #
. . . # .
# . # . .
# # . . .
# # # . .`;
case ArrowNames.West: return `
# # # . .`);
case ArrowNames.West: return images.createImage(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .`;
case ArrowNames.NorthWest: return `
. . # . .`);
case ArrowNames.NorthWest: return images.createImage(`
# # # . .
# # . . .
# . # . .
. . . # .
. . . . #`;
default: return `
. . . . #`);
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`;
}
}
function getIcon(i: IconNames): string {
switch (i) {
case IconNames.Heart : return `
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`;
case IconNames.SmallHeart : return `
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`;
//faces
case IconNames.Happy: return `
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`;
case IconNames.Sad: return `
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`;
case IconNames.Confused: return `
. . . . .
. # . # .
. . . . .
. # . # .
# . # . #`;
case IconNames.Angry: return `
# . . . #
. # . # .
. . . . .
# # # # #
# . # . #`;
case IconNames.Asleep: return `
. . . . .
# # . # #
. . . . .
. # # # .
. . . . .`;
case IconNames.Surprised: return `
. # . # .
. . . . .
. . # . .
. # . # .
. . # . .`;
case IconNames.Silly: return `
# . . . #
. . . . .
# # # # #
. . . # #
. . . # #`;
case IconNames.Fabulous: return `
# # # # #
# # . # #
. . . . .
. # . # .
. # # # .`;
case IconNames.Meh: return `
# # . # #
. . . . .
. . . # .
. . # . .
. # . . .`;
case IconNames.Yes: return `
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .`;
case IconNames.No: return `
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #`;
case IconNames.Triangle: return `
. . . . .
. . # . .
. # . # .
# # # # #
. . . . .`;
case IconNames.LeftTriangle: return `
# . . . .
# # . . .
# . # . .
# . . # .
# # # # #`;
case IconNames.Chessboard: return `
. # . # .
# . # . #
. # . # .
# . # . #
. # . # .`;
case IconNames.Diamond: return `
. . # . .
. # . # .
# . . . #
. # . # .
. . # . .`;
case IconNames.SmallDiamond: return `
. . . . .
. . # . .
. # . # .
. . # . .
. . . . .`;
case IconNames.Square: return `
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`;
case IconNames.SmallSquare: return `
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .`;
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return `
# # . # #
# # # # #
. # # # .
. # # # .
. # # # .`;
case IconNames.Rollerskate: return `
. . . # #
. . . # #
# # # # #
# # # # #
. # . # .`;
case IconNames.Duck: return `
. # # . .
# # # . .
. # # # #
. # # # .
. .. . .`;
case IconNames.House: return `
. . # . .
. # # # .
# # # # #
. # # # .
. # . # .`;
case IconNames.Tortoise: return `
. . . . .
. # # # .
# # # # #
. # . # .
. . . . .`;
case IconNames.Butterfly: return `
# # . # #
# # # # #
. . # . .
# # # # #
# # . # #`;
case IconNames.StickFigure: return `
. . # . .
# # # # #
. . # . .
. # . # .
# . . . #`;
case IconNames.Ghost: return `
. # # # .
# . # . #
# # # # #
# # # # #
# . # . #`;
case IconNames.Sword: return `
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .`;
case IconNames.Giraffe: return `
# # . . .
. # . . .
. # . . .
. # # # .
. # . # .`;
case IconNames.Skull: return `
. # # # .
# . # . #
# # # # #
. # # # .
. # # # .`;
case IconNames.Umbrella: return `
. # # # .
# # # # #
. . # . .
# . # . .
# # # . .`;
case IconNames.Snake: return `
# # . . .
# # . # #
. # . # .
. # # # .
. . . . .`;
// animals
case IconNames.Rabbit: return `
# . # . .
# . # . .
# # # # .
# # . # .
# # # # .`;
case IconNames.Cow: return `
# . . . #
# . . . #
# # # # #
. # # # .
. . # . .`;
// musical notes
case IconNames.QuarterNote: return `
. . # . .
. . # . .
. . # . .
# # # . .
# # # . .`;
case IconNames.EigthNote: return `
. . # . .
. . # # .
. . # . #
# # # . .
# # # . .`;
// other icons
case IconNames.Pitchfork: return `
# . # . #
# . # . #
# # # # #
. . # . .
. . # . .`;
case IconNames.Pacman: return `
. # # # #
# # # # .
# # # . .
# # # # .
. # # # #`;
case IconNames.Target: return `
. . # . .
. # # # .
# # . # #
. # # # .
. . # . .`;
default: return `
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`;
`);
}
}
//% weight=50 blockGap=8
//% help=images/icon-image
//% blockId=builtin_image block="icon image %i"
//% i.fieldEditor="gridpicker"
//% i.fieldOptions.width="400" i.fieldOptions.columns="5"
//% i.fieldOptions.itemColour="black" i.fieldOptions.tooltips="true"
export function iconImage(i: IconNames): Image {
switch (i) {
case IconNames.Heart: return images.createImage(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
case IconNames.SmallHeart: return images.createImage(`
. . . . .
. # . # .
. # # # .
. . # . .
. . . . .`);
//faces
case IconNames.Happy: return images.createImage(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .`);
case IconNames.Sad: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
case IconNames.Confused: return images.createImage(`
. . . . .
. # . # .
. . . . .
. # . # .
# . # . #`);
case IconNames.Angry: return images.createImage(`
# . . . #
. # . # .
. . . . .
# # # # #
# . # . #`);
case IconNames.Asleep: return images.createImage(`
. . . . .
# # . # #
. . . . .
. # # # .
. . . . .`);
case IconNames.Surprised: return images.createImage(`
. # . # .
. . . . .
. . # . .
. # . # .
. . # . .`);
case IconNames.Silly: return images.createImage(`
# . . . #
. . . . .
# # # # #
. . . # #
. . . # #`);
case IconNames.Fabulous: return images.createImage(`
# # # # #
# # . # #
. . . . .
. # . # .
. # # # .`);
case IconNames.Meh: return images.createImage(`
# # . # #
. . . . .
. . . # .
. . # . .
. # . . .`);
case IconNames.Yes: return images.createImage(`
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .`);
case IconNames.No: return images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #`);
case IconNames.Triangle: return images.createImage(`
. . . . .
. . # . .
. # . # .
# # # # #
. . . . .`);
case IconNames.LeftTriangle: return images.createImage(`
# . . . .
# # . . .
# . # . .
# . . # .
# # # # #`);
case IconNames.Chessboard: return images.createImage(`
. # . # .
# . # . #
. # . # .
# . # . #
. # . # .`);
case IconNames.Diamond: return images.createImage(`
. . # . .
. # . # .
# . . . #
. # . # .
. . # . .`);
case IconNames.SmallDiamond: return images.createImage(`
. . . . .
. . # . .
. # . # .
. . # . .
. . . . .`);
case IconNames.Square: return images.createImage(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #`);
case IconNames.SmallSquare: return images.createImage(`
. . . . .
. # # # .
. # . # .
. # # # .
. . . . .`);
case IconNames.Scissors: return images.createImage(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #`);
// The following images were designed by Abbie Brooks.
case IconNames.TShirt: return images.createImage(`
# # . # #
# # # # #
. # # # .
. # # # .
. # # # .`);
case IconNames.Rollerskate: return images.createImage(`
. . . # #
. . . # #
# # # # #
# # # # #
. # . # .`);
case IconNames.Duck: return images.createImage(`
. # # . .
# # # . .
. # # # #
. # # # .
. . . . .`);
case IconNames.House: return images.createImage(`
. . # . .
. # # # .
# # # # #
. # # # .
. # . # .`);
case IconNames.Tortoise: return images.createImage(`
. . . . .
. # # # .
# # # # #
. # . # .
. . . . .`);
case IconNames.Butterfly: return images.createImage(`
# # . # #
# # # # #
. . # . .
# # # # #
# # . # #`);
case IconNames.StickFigure: return images.createImage(`
. . # . .
# # # # #
. . # . .
. # . # .
# . . . #`);
case IconNames.Ghost: return images.createImage(`
. # # # .
# . # . #
# # # # #
# # # # #
# . # . #`);
case IconNames.Sword: return images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .`);
case IconNames.Giraffe: return images.createImage(`
# # . . .
. # . . .
. # . . .
. # # # .
. # . # .`);
case IconNames.Skull: return images.createImage(`
. # # # .
# . # . #
# # # # #
. # # # .
. # # # .`);
case IconNames.Umbrella: return images.createImage(`
. # # # .
# # # # #
. . # . .
# . # . .
# # # . .`);
case IconNames.Snake: return images.createImage(`
# # . . .
# # . # #
. # . # .
. # # # .
. . . . .`);
// animals
case IconNames.Rabbit: return images.createImage(`
# . # . .
# . # . .
# # # # .
# # . # .
# # # # .`);
case IconNames.Cow: return images.createImage(`
# . . . #
# . . . #
# # # # #
. # # # .
. . # . .`);
// musical notes
case IconNames.QuarterNote: return images.createImage(`
. . # . .
. . # . .
. . # . .
# # # . .
# # # . .`);
case IconNames.EigthNote: return images.createImage(`
. . # . .
. . # # .
. . # . #
# # # . .
# # # . .`);
// other icons
case IconNames.Pitchfork: return images.createImage(`
# . # . #
# . # . #
# # # # #
. . # . .
. . # . .`);
case IconNames.Target: return images.createImage(`
. . # . .
. # # # .
# # . # #
. # # # .
. . # . .`);
default: return images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`);
}
}
//% weight=50 blockGap=8
//% help=images/arrow-number
//% blockId=device_arrow block="%arrow"
//% shim=TD_ID
export function arrowNumber(arrow: ArrowNames): number {
return arrow;
}
//% weight=50 blockGap=8
//% blockId=builtin_arrow_image block="arrow image %i=device_arrow"
export function arrowImage(i: ArrowNames): Image {
let res = images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
return set(res, getArrow(i));
}
//% weight=50 blockGap=8
//% blockId=builtin_image block="icon image %i"
export function iconImage(i: IconNames): Image {
let res = images.createImage(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
return set(res, getIcon(i));
}
function set(res: Image, s: string) {
let j = 0;
for (let x of s) {
if (x == "." || x == "#") {
res.setPixel(j % 5, j / 5, x == "#")
j++
}
}
return res
}
}

View File

@ -64,12 +64,12 @@ namespace ImageMethods {
* @param frameOffset x offset moved on each animation step, eg: 1, 2, 5
* @param interval time between each animation step in milli seconds, eg: 200
*/
//% help=images/show-image weight=79 async blockNamespace=images
//% help=images/scroll-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix"
void scrollImage(Image id, int frameOffset, int interval) {
MicroBitImage i(id);
uBit.display.animate(i, interval, frameOffset, MICROBIT_DISPLAY_WIDTH - 1);
uBit.display.animate(i, interval, frameOffset, MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, 0);
}

View File

@ -105,15 +105,55 @@ enum class Gesture {
* Raised when a 6G shock is detected
*/
//% block="6g"
SixG = MICROBIT_ACCELEROMETER_EVT_6G
SixG = MICROBIT_ACCELEROMETER_EVT_6G,
/**
* Raised when a 8G shock is detected
*/
//% block="8g"
EightG = MICROBIT_ACCELEROMETER_EVT_8G
};
//% color=#C90072 weight=99 icon="\uf192"
enum class MesDpadButtonInfo {
//% block="A down"
ADown = MES_DPAD_BUTTON_A_DOWN,
//% block="A up"
AUp = MES_DPAD_BUTTON_A_UP,
//% block="B down"
BDown = MES_DPAD_BUTTON_B_DOWN,
//% block="B up"
BUp = MES_DPAD_BUTTON_B_UP,
//% block="C down"
CDown = MES_DPAD_BUTTON_C_DOWN,
//% block="C up"
CUp = MES_DPAD_BUTTON_C_UP,
//% block="D down"
DDown = MES_DPAD_BUTTON_D_DOWN,
//% block="D up"
DUp = MES_DPAD_BUTTON_D_UP,
//% block="1 down"
_1Down = MES_DPAD_BUTTON_1_DOWN,
//% block="1 up"
_1Up = MES_DPAD_BUTTON_1_UP,
//% block="2 down"
_2Down = MES_DPAD_BUTTON_2_DOWN,
//% block="2 up"
_2Up = MES_DPAD_BUTTON_2_UP,
//% block="3 down"
_3Down = MES_DPAD_BUTTON_3_DOWN,
//% block="3 up"
_3Up = MES_DPAD_BUTTON_3_UP,
//% block="4 down"
_4Down = MES_DPAD_BUTTON_4_DOWN,
//% block="4 up"
_4Up = MES_DPAD_BUTTON_4_UP,
};
//% color=#B4009E weight=99 icon="\uf192"
namespace input {
/**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
* @param button TODO
* @param body TODO
* Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button the button that needs to be pressed
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed"
@ -124,26 +164,29 @@ namespace input {
/**
* Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO
* @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer"
//% NAME.fieldEditor="gridpicker" NAME.fieldOptions.columns=4
void onGesture(Gesture gesture, Action body) {
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(6);
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
int gi = (int)gesture;
if (gi == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
uBit.accelerometer.setRange(4);
else if ((gi == MICROBIT_ACCELEROMETER_EVT_6G || gi == MICROBIT_ACCELEROMETER_EVT_8G) && uBit.accelerometer.getRange() < 6)
uBit.accelerometer.setRange(8);
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
registerWithDal(MICROBIT_ID_GESTURE, gi, body);
}
/**
* Do something when a pin is pressed.
* @param name the pin that needs to be pressed
* Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed"
//% blockId=device_pin_event block="on pin %name|pressed"
void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name);
if (!pin) return;
@ -155,7 +198,7 @@ namespace input {
/**
* Do something when a pin is released.
* @param name the pin that needs to be released
* @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=8
@ -172,6 +215,7 @@ namespace input {
/**
* Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/
//% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed"
@ -190,7 +234,7 @@ namespace input {
/**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch
* @param name pin used to detect the touch, eg: TouchPin.P0
*/
//% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
@ -205,7 +249,7 @@ namespace input {
double y = uBit.accelerometer.getY();
double z = uBit.accelerometer.getZ();
return (int)sqrt(x*x+y*y+z*z);
}
}
/**
* Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)
@ -296,18 +340,31 @@ namespace input {
/**
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50
//% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true
int runningTime() {
return system_timer_current_time();
}
/**
* 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
int runningTimeMicros() {
return system_timer_current_time_us();
}
/**
* Obsolete, compass calibration is automatic.
*/
//% help=input/calibrate weight=0
void calibrate() { }
//% help=input/calibrate-compass advanced=true
//% blockId="input_compass_calibrate" block="calibrate compass"
void calibrateCompass() {
uBit.compass.calibrate();
}
/**
* Sets the accelerometer sample range in gravities.

View File

@ -13,14 +13,34 @@ namespace led {
/**
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO
* @param y TODO
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
void plot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 1);
uBit.display.image.setPixelValue(x, y, 0xff);
}
/**
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
*/
//% help=led/plot-brightness weight=78
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
//% advanced=true
void plotBrightness(int x, int y, int brightness) {
brightness = max(0, min(0xff, brightness));
// enable greyscale as needed
if (brightness != 0 && brightness != 0xff && uBit.display.getDisplayMode() != DISPLAY_MODE_GREYSCALE)
uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE);
uBit.display.image.setPixelValue(x, y, brightness);
}
/**
@ -31,6 +51,7 @@ namespace led {
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
void unplot(int x, int y) {
uBit.display.image.setPixelValue(x, y, 0);
}
@ -43,6 +64,7 @@ namespace led {
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
bool point(int x, int y) {
int pix = uBit.display.image.getPixelValue(x, y);
return pix > 0;
@ -67,6 +89,7 @@ namespace led {
//% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix"
//% advanced=true
//% value.min=0 value.max=255
void setBrightness(int value) {
uBit.display.setBrightness(value);
}
@ -92,10 +115,18 @@ namespace led {
uBit.display.setDisplayMode((DisplayMode)mode);
}
/**
* Gets the current display mode
*/
//% weight=1 parts="ledmatrix" advanced=true
DisplayMode_ displayMode() {
return (DisplayMode_)uBit.display.getDisplayMode();
}
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable
//% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix"
void enable(bool on) {
if (on) uBit.display.enable();

119
libs/core/melodies.ts Normal file
View File

@ -0,0 +1,119 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers, as listed
in the accompanying AUTHORS file
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Melodies from file microbitmusictunes.c https://github.com/bbcmicrobit/MicroPython
enum Melodies {
//% block="dadadum" blockIdentity=music.builtInMelody
Dadadadum = 0,
//% block="entertainer" blockIdentity=music.builtInMelody
Entertainer,
//% block="prelude" blockIdentity=music.builtInMelody
Prelude,
//% block="ode" blockIdentity=music.builtInMelody
Ode,
//% block="nyan" blockIdentity=music.builtInMelody
Nyan,
//% block="ringtone" blockIdentity=music.builtInMelody
Ringtone,
//% block="funk" blockIdentity=music.builtInMelody
Funk,
//% block="blues" blockIdentity=music.builtInMelody
Blues,
//% block="birthday" blockIdentity=music.builtInMelody
Birthday,
//% block="wedding" blockIdentity=music.builtInMelody
Wedding,
//% block="funereal" blockIdentity=music.builtInMelody
Funeral,
//% block="punchline" blockIdentity=music.builtInMelody
Punchline,
//% block="baddy" blockIdentity=music.builtInMelody
Baddy,
//% block="chase" blockIdentity=music.builtInMelody
Chase,
//% block="ba ding" blockIdentity=music.builtInMelody
BaDing,
//% block="wawawawaa" blockIdentity=music.builtInMelody
Wawawawaa,
//% block="jump up" blockIdentity=music.builtInMelody
JumpUp,
//% block="jump down" blockIdentity=music.builtInMelody
JumpDown,
//% block="power up" blockIdentity=music.builtInMelody
PowerUp,
//% block="power down" blockIdentity=music.builtInMelody
PowerDown,
}
namespace music {
export function getMelody(melody: Melodies): string[] {
switch (melody) {
case Melodies.Dadadadum:
return ['r4:2', 'g', 'g', 'g', 'eb:8', 'r:2', 'f', 'f', 'f', 'd:8'];
case Melodies.Entertainer:
return ['d4:1', 'd#', 'e', 'c5:2', 'e4:1', 'c5:2', 'e4:1', 'c5:3', 'c:1', 'd', 'd#', 'e', 'c', 'd', 'e:2', 'b4:1', 'd5:2', 'c:4'];
case Melodies.Prelude:
return ['c4:1', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'd', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'b3', 'd4', 'g', 'd5', 'f', 'g4', 'd5', 'f', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e', 'c4', 'e', 'g', 'c5', 'e', 'g4', 'c5', 'e'];
case Melodies.Ode:
return ['e4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'e:6', 'd:2', 'd:8', 'e:4', 'e', 'f', 'g', 'g', 'f', 'e', 'd', 'c', 'c', 'd', 'e', 'd:6', 'c:2', 'c:8'];
case Melodies.Nyan:
return ['f#5:2', 'g#', 'c#:1', 'd#:2', 'b4:1', 'd5:1', 'c#', 'b4:2', 'b', 'c#5', 'd', 'd:1', 'c#', 'b4:1', 'c#5:1', 'd#', 'f#', 'g#', 'd#', 'f#', 'c#', 'd', 'b4', 'c#5', 'b4', 'd#5:2', 'f#', 'g#:1', 'd#', 'f#', 'c#', 'd#', 'b4', 'd5', 'd#', 'd', 'c#', 'b4', 'c#5', 'd:2', 'b4:1', 'c#5', 'd#', 'f#', 'c#', 'd', 'c#', 'b4', 'c#5:2', 'b4', 'c#5', 'b4', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'c#5', 'd#', 'b4', 'e5', 'd#', 'e', 'f#', 'b4:2', 'b', 'f#:1', 'g#', 'b', 'f#', 'e5', 'd#', 'c#', 'b4', 'f#', 'd#', 'e', 'f#', 'b:2', 'f#:1', 'g#', 'b:2', 'f#:1', 'g#', 'b', 'b', 'c#5', 'd#', 'b4', 'f#', 'g#', 'f#', 'b:2', 'b:1', 'a#', 'b', 'f#', 'g#', 'b', 'e5', 'd#', 'e', 'f#', 'b4:2', 'c#5'];
case Melodies.Ringtone:
return ['c4:1', 'd', 'e:2', 'g', 'd:1', 'e', 'f:2', 'a', 'e:1', 'f', 'g:2', 'b', 'c5:4'];
case Melodies.Funk:
return ['c2:2', 'c', 'd#', 'c:1', 'f:2', 'c:1', 'f:2', 'f#', 'g', 'c', 'c', 'g', 'c:1', 'f#:2', 'c:1', 'f#:2', 'f', 'd#'];
case Melodies.Blues:
return ['c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'f', 'a', 'c3', 'd', 'd#', 'd', 'c', 'a2', 'c2:2', 'e', 'g', 'a', 'a#', 'a', 'g', 'e', 'g', 'b', 'd3', 'f', 'f2', 'a', 'c3', 'd#', 'c2:2', 'e', 'g', 'e', 'g', 'f', 'e', 'd'];
case Melodies.Birthday:
return ['c4:3', 'c:1', 'd:4', 'c:4', 'f', 'e:8', 'c:3', 'c:1', 'd:4', 'c:4', 'g', 'f:8', 'c:3', 'c:1', 'c5:4', 'a4', 'f', 'e', 'd', 'a#:3', 'a#:1', 'a:4', 'f', 'g', 'f:8'];
case Melodies.Wedding:
return ['c4:4', 'f:3', 'f:1', 'f:8', 'c:4', 'g:3', 'e:1', 'f:8', 'c:4', 'f:3', 'a:1', 'c5:4', 'a4:3', 'f:1', 'f:4', 'e:3', 'f:1', 'g:8'];
case Melodies.Funeral:
return ['c3:4', 'c:3', 'c:1', 'c:4', 'd#:3', 'd:1', 'd:3', 'c:1', 'c:3', 'b2:1', 'c3:4'];
case Melodies.Punchline:
return ['c4:3', 'g3:1', 'f#', 'g', 'g#:3', 'g', 'r', 'b', 'c4'];
case Melodies.Baddy:
return ['c3:3', 'r', 'd:2', 'd#', 'r', 'c', 'r', 'f#:8'];
case Melodies.Chase:
return ['a4:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:1', 'b', 'c5', 'b4', 'a:2', 'r', 'a:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e', 'b4:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:1', 'c5', 'd', 'c', 'b4:2', 'r', 'b:2', 'e5', 'd#', 'e', 'f', 'e', 'd#', 'e'];
case Melodies.BaDing:
return ['b5:1', 'e6:3'];
case Melodies.Wawawawaa:
return ['e3:3', 'r:1', 'd#:3', 'r:1', 'd:4', 'r:1', 'c#:8'];
case Melodies.JumpUp:
return ['c5:1', 'd', 'e', 'f', 'g'];
case Melodies.JumpDown:
return ['g5:1', 'f', 'e', 'd', 'c'];
case Melodies.PowerUp:
return ['g4:1', 'c5', 'e', 'g:2', 'e:1', 'g:3'];
case Melodies.PowerDown:
return ['g5:1', 'd#', 'c', 'g4:2', 'b:1', 'c5:3'];
default:
return [];
}
}
}

View File

@ -6,10 +6,9 @@ namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
//%
//% parts="speaker" async useEnumVal=1
void playTone(int frequency, int ms) {
void speakerPlayTone(int frequency, int ms) {
if(frequency > 0) uBit.soundmotor.soundOn(frequency);
else uBit.soundmotor.soundOff();
if(ms > 0) {

View File

@ -119,15 +119,82 @@ enum BeatFraction {
//% block="1/8"
Eighth = 8,
//% block="1/16"
Sixteenth = 16
Sixteenth = 16,
//% block="2"
Double = 32,
//% block="4",
Breve = 64
}
enum MelodyOptions {
//% block="once""
Once = 1,
//% block="forever"
Forever = 2,
//% block="once in background"
OnceInBackground = 4,
//% block="forever in background"
ForeverInBackground = 8
}
enum MusicEvent {
//% block="melody note played"
MelodyNotePlayed = 1,
//% block="melody started"
MelodyStarted = 2,
//% block="melody ended"
MelodyEnded = 3,
//% block="melody repeated"
MelodyRepeated = 4,
//% block="background melody note played"
BackgroundMelodyNotePlayed = MelodyNotePlayed | 0xf0,
//% block="background melody started"
BackgroundMelodyStarted = MelodyStarted | 0xf0,
//% block="background melody ended"
BackgroundMelodyEnded = MelodyEnded | 0xf0,
//% block="background melody repeated"
BackgroundMelodyRepeated = MelodyRepeated | 0xf0,
//% block="background melody paused"
BackgroundMelodyPaused = 5 | 0xf0,
//% block="background melody resumed"
BackgroundMelodyResumed = 6 | 0xf0
}
/**
* Generation of music tones through pin ``P0``.
* Generation of music tones.
*/
//% color=#DF4600 weight=98 icon="\uf025"
namespace music {
let beatsPerMinute: number = 120;
let freqTable: number[] = [];
let _playTone: (frequency: number, duration: number) => void;
const MICROBIT_MELODY_ID = 2000;
/**
* Plays a tone through pin ``P0`` for the given duration.
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" blockGap=8
//% parts="headphone"
//% useEnumVal=1
export function playTone(frequency: number, ms: number): void {
if (_playTone) _playTone(frequency, ms);
else speakerPlayTone(frequency, ms);
}
/**
* Plays a tone through pin ``P0``.
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
//% parts="headphone"
//% useEnumVal=1
export function ringTone(frequency: number): void {
playTone(frequency, 0);
}
/**
* Rests (plays nothing) for a specified time through pin ``P0``.
@ -135,38 +202,28 @@ namespace music {
*/
//% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat"
//% parts="speaker"
//% parts="headphone"
export function rest(ms: number): void {
playTone(0, ms);
}
/**
* Plays a tone through ``speaker``.
* @param frequency pitch of the tone to play in Hertz (Hz)
*/
//% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" blockGap=8
//% parts="speaker" async
//% useEnumVal=1
export function ringTone(frequency: number) {
playTone(frequency, 0);
}
/**
* Gets the frequency of a note.
* @param name the note name
* @param name the note name, eg: Note.C
*/
//% weight=50 help=music/note-frequency
//% blockId=device_note block="%note"
//% shim=TD_ID blockHidden=true
//% blockFieldEditor="note_editor"
//% useEnumVal = 1
//% shim=TD_ID
//% note.fieldEditor="note" note.defl="262"
//% useEnumVal=1
export function noteFrequency(name: Note): number {
return name;
}
function init() {
if (beatsPerMinute <= 0) beatsPerMinute = 120;
if (freqTable.length == 0) freqTable = [31, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 92, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, 4186]
}
/**
@ -178,11 +235,15 @@ namespace music {
init();
if (fraction == null) fraction = BeatFraction.Whole;
let beat = 60000 / beatsPerMinute;
if (fraction == BeatFraction.Whole) return beat;
else if (fraction == BeatFraction.Half) return beat / 2;
else if (fraction == BeatFraction.Quarter) return beat / 4;
else if (fraction == BeatFraction.Eighth) return beat / 8;
else return beat / 16;
switch (fraction) {
case BeatFraction.Half: return beat / 2;
case BeatFraction.Quarter: return beat / 4;
case BeatFraction.Eighth: return beat / 8;
case BeatFraction.Sixteenth: return beat / 16;
case BeatFraction.Double: return beat * 2;
case BeatFraction.Breve: return beat * 4;
default: return beat;
}
}
/**
@ -212,10 +273,166 @@ namespace music {
*/
//% help=music/set-tempo weight=38
//% blockId=device_set_tempo block="set tempo to (bpm)|%value"
//% bpm.min=4 bpm.max=400
export function setTempo(bpm: number): void {
init();
if (bpm > 0) {
beatsPerMinute = Math.max(1, bpm);
}
}
let currentMelody: Melody;
let currentBackgroundMelody: Melody;
/**
* Gets the melody array of a built-in melody.
* @param name the note name, eg: Note.C
*/
//% weight=50 help=music/builtin-melody
//% blockId=device_builtin_melody block="%melody"
//% blockHidden=true
export function builtInMelody(melody: Melodies): string[] {
return getMelody(melody);
}
/**
* Registers code to run on various melody events
*/
//% blockId=melody_on_event block="music on %value"
//% help=music/on-event weight=59
export function onEvent(value: MusicEvent, handler: Action) {
control.onEvent(MICROBIT_MELODY_ID, value, handler);
}
/**
* Starts playing a melody.
* Notes are expressed as a string of characters with this format: NOTE[octave][:duration]
* @param melodyArray the melody array to play, eg: ['g5:1']
* @param options melody options, once / forever, in the foreground / background
*/
//% help=music/begin-melody weight=60 blockGap=8
//% blockId=device_start_melody block="start melody %melody=device_builtin_melody| repeating %options"
//% parts="headphone"
export function beginMelody(melodyArray: string[], options: MelodyOptions = 1) {
init();
if (currentMelody != undefined) {
if (((options & MelodyOptions.OnceInBackground) == 0)
&& ((options & MelodyOptions.ForeverInBackground) == 0)
&& currentMelody.background) {
currentBackgroundMelody = currentMelody;
currentMelody = null;
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyPaused);
}
if (currentMelody)
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);
currentMelody = new Melody(melodyArray, options);
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);
} else {
currentMelody = new Melody(melodyArray, options);
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyStarted : MusicEvent.MelodyStarted);
// Only start the fiber once
control.inBackground(() => {
while (currentMelody.hasNextNote()) {
playNextNote(currentMelody);
if (!currentMelody.hasNextNote() && currentBackgroundMelody) {
// Swap the background melody back
currentMelody = currentBackgroundMelody;
currentBackgroundMelody = null;
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.MelodyEnded);
control.raiseEvent(MICROBIT_MELODY_ID, MusicEvent.BackgroundMelodyResumed);
}
}
control.raiseEvent(MICROBIT_MELODY_ID, currentMelody.background ? MusicEvent.BackgroundMelodyEnded : MusicEvent.MelodyEnded);
currentMelody = null;
})
}
}
/**
* Sets a custom playTone function for playing melodies
*/
//% help=music/set-play-tone
//% advanced=true
export function setPlayTone(f: (frequency: number, duration: number) => void) {
_playTone = f;
}
function playNextNote(melody: Melody): void {
// cache elements
let currNote = melody.nextNote();
let currentPos = melody.currentPos;
let currentDuration = melody.currentDuration;
let currentOctave = melody.currentOctave;
let note: number;
let isrest: boolean = false;
let beatPos: number;
let parsingOctave: boolean = true;
for (let pos = 0; pos < currNote.length; pos++) {
let noteChar = currNote.charAt(pos);
switch (noteChar) {
case 'c': case 'C': note = 1; break;
case 'd': case 'D': note = 3; break;
case 'e': case 'E': note = 5; break;
case 'f': case 'F': note = 6; break;
case 'g': case 'G': note = 8; break;
case 'a': case 'A': note = 10; break;
case 'b': case 'B': note = 12; break;
case 'r': case 'R': isrest = true; break;
case '#': note++; break;
case 'b': note--; break;
case ':': parsingOctave = false; beatPos = pos; break;
default: if (parsingOctave) currentOctave = parseInt(noteChar);
}
}
if (!parsingOctave) {
currentDuration = parseInt(currNote.substr(beatPos + 1, currNote.length - beatPos));
}
let beat = (60000 / beatsPerMinute) / 4;
if (isrest) {
music.rest(currentDuration * beat)
} else {
let keyNumber = note + (12 * (currentOctave - 1));
let frequency = keyNumber >= 0 && keyNumber < freqTable.length ? freqTable[keyNumber] : 0;
music.playTone(frequency, currentDuration * beat);
}
melody.currentDuration = currentDuration;
melody.currentOctave = currentOctave;
const repeating = melody.repeating && currentPos == melody.melodyArray.length - 1;
melody.currentPos = repeating ? 0 : currentPos + 1;
control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyNotePlayed : MusicEvent.MelodyNotePlayed);
if (repeating)
control.raiseEvent(MICROBIT_MELODY_ID, melody.background ? MusicEvent.BackgroundMelodyRepeated : MusicEvent.MelodyRepeated);
}
class Melody {
public melodyArray: string[];
public currentDuration: number;
public currentOctave: number;
public currentPos: number;
public repeating: boolean;
public background: boolean;
constructor(melodyArray: string[], options: MelodyOptions) {
this.melodyArray = melodyArray;
this.repeating = ((options & MelodyOptions.Forever) != 0);
this.repeating = this.repeating ? true : ((options & MelodyOptions.ForeverInBackground) != 0)
this.background = ((options & MelodyOptions.OnceInBackground) != 0);
this.background = this.background ? true : ((options & MelodyOptions.ForeverInBackground) != 0);
this.currentDuration = 4; //Default duration (Crotchet)
this.currentOctave = 4; //Middle octave
this.currentPos = 0;
}
hasNextNote() {
return this.repeating || this.currentPos < this.melodyArray.length;
}
nextNote(): string {
const currentNote = this.melodyArray[this.currentPos];
return currentNote;
}
}
}

View File

@ -102,42 +102,52 @@ namespace pins {
/**
* Read the specified pin or connector as either 0 or 1
* @param name pin to read from
* @param name pin to read from, eg: DigitalPin.P0
*/
//% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
int digitalReadPin(DigitalPin name) {
PINREAD(getDigitalValue());
}
/**
* Set a pin or connector value to either 0 or 1.
* @param name pin to write to
* @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0
*/
//% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
void digitalWritePin(DigitalPin name, int value) {
PINOP(setDigitalValue(value));
}
/**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to
* @param name pin to write to, eg: AnalogPin.P0
*/
//% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
int analogReadPin(AnalogPin name) {
PINREAD(getAnalogValue());
}
/**
* Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to
* @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/
//% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void analogWritePin(AnalogPin name, int value) {
PINOP(setAnalogValue(value));
}
@ -145,20 +155,26 @@ namespace pins {
/**
* 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 name analog pin to set period to
* @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000
*/
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false"
void analogSetPeriod(AnalogPin name, int micros) {
PINOP(setAnalogPeriodUs(micros));
}
/**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/
//% help=pins/on-pulsed weight=22 blockGap=8
//% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void onPulsed(DigitalPin name, PulseValue pulse, Action body) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return;
@ -170,7 +186,7 @@ namespace pins {
/**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/
//% help=pins/pulse-duration
//% help=pins/pulse-duration advanced=true
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 blockGap=8
int pulseDuration() {
@ -179,12 +195,15 @@ namespace pins {
/**
* Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse
* @param value the value of the pulse (default high)
* @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds
*/
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20
//% weight=20 advanced=true
//% help=pins/pulse-in
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300"
int pulseIn(DigitalPin name, PulseValue value, int maxDuration = 2000000) {
MicroBitPin* pin = getPin((int)name);
if (!pin) return 0;
@ -219,12 +238,15 @@ namespace pins {
/**
* 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 name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0
*/
//% help=pins/servo-write-pin weight=20
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0
//% value.min=0 value.max=180
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void servoWritePin(AnalogPin name, int value) {
fixMotorIssue(name);
PINOP(setServoValue(value));
@ -237,6 +259,8 @@ namespace pins {
*/
//% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
//% value.fieldEditor="gridpicker" value.fieldOptions.columns=4
//% value.fieldOptions.tooltips="false"
void servoSetPulse(AnalogPin name, int micros) {
fixMotorIssue(name);
PINOP(setServoPulseUs(micros));
@ -246,48 +270,52 @@ namespace pins {
MicroBitPin* pitchPin = NULL;
/**
* Sets the pin used when using `pins->analog pitch`.
* @param name TODO
* Sets the pin used when using `analog pitch` or music.
* @param name pin to modulate pitch from
*/
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch weight=3 advanced=true
//% help=pins/analog-set-pitch-pin weight=3 advanced=true
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false"
void analogSetPitchPin(AnalogPin name) {
pitchPin = getPin((int)name);
}
pitchPin = getPin((int)name);
}
/**
* 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
*/
* Emits a Pulse-width modulation (PWM) signal to the current pitch pin. Use `analog set pitch pin` to define the pitch pin.
* @param frequency frequency to modulate in Hz.
* @param ms duration of the pitch in milli seconds.
*/
//% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms"
//% help=pins/analog-pitch weight=4 async advanced=true blockGap=8
void analogPitch(int frequency, int ms) {
if (pitchPin == NULL)
analogSetPitchPin(AnalogPin::P1);
if (frequency <= 0) {
pitchPin->setAnalogValue(0);
} else {
pitchPin->setAnalogValue(512);
pitchPin->setAnalogPeriodUs(1000000/frequency);
}
if (ms > 0) {
fiber_sleep(ms);
if (pitchPin == NULL)
analogSetPitchPin(AnalogPin::P1);
if (frequency <= 0) {
pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think
wait_ms(5);
}
} else {
pitchPin->setAnalogValue(512);
pitchPin->setAnalogPeriodUs(1000000/frequency);
}
if (ms > 0) {
fiber_sleep(ms);
pitchPin->setAnalogValue(0);
// TODO why do we use wait_ms() here? it's a busy wait I think
wait_ms(5);
}
}
/**
* Configures the pull of this pin.
* @param name pin to set the pull mode on
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone
* @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/
//% help=pins/set-pull weight=3
//% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void setPull(DigitalPin name, PinPullMode pull) {
PinMode m = pull == PinPullMode::PullDown
? PinMode::PullDown
@ -304,6 +332,8 @@ namespace pins {
*/
//% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300"
void setEvents(DigitalPin name, PinEventType type) {
getPin((int)name)->eventOn((int)type);
}
@ -337,10 +367,10 @@ namespace pins {
{
uBit.i2c.write(address << 1, (char*)buf->payload, buf->length, repeat);
}
SPI* spi = NULL;
SPI* allocSPI() {
if (spi == NULL)
if (NULL == spi)
spi = new SPI(MOSI, MISO, SCK);
return spi;
}
@ -349,11 +379,54 @@ namespace pins {
* Write to the SPI slave and return the response
* @param value Data to be sent to the SPI slave
*/
//% help=pins/spi-write weight=5
//% help=pins/spi-write weight=5 advanced=true
//% blockId=spi_write block="spi write %value"
int spiWrite(int value) {
auto p = allocSPI();
return p->write(value);
}
/**
* Sets the SPI frequency
* @param frequency the clock frequency, eg: 1000000
*/
//% help=pins/spi-frequency weight=4 advanced=true
//% blockId=spi_frequency block="spi frequency %frequency"
void spiFrequency(int frequency) {
auto p = allocSPI();
p->frequency(frequency);
}
/**
* Sets the SPI bits and mode
* @param bits the number of bits, eg: 8
* @param mode the mode, eg: 3
*/
//% help=pins/spi-format weight=3 advanced=true
//% blockId=spi_format block="spi format|bits %bits|mode %mode"
void spiFormat(int bits, int mode) {
auto p = allocSPI();
p->format(bits, mode);
}
/**
* Sets the MOSI, MISO, SCK pins used by the SPI instance
*
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
//% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4
//% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="300"
//% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4
//% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="300"
//% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4
//% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="300"
void spiPins(DigitalPin mosi, DigitalPin miso, DigitalPin sck) {
if (NULL != spi) {
delete spi;
spi = NULL;
}
spi = new SPI(getPin((int)mosi)->name, getPin((int)miso)->name, getPin((int)sck)->name);
}
}

View File

@ -146,16 +146,16 @@ namespace pxt {
#ifdef DEBUG_BUILD
printf("In Segment::get index:%u\n", i);
this->print();
#endif
#endif
if (i < length)
{
return data[i];
return data[i];
}
return Segment::DefaultValue;
}
void Segment::set(uint32_t i, uint32_t value)
void Segment::set(uint32_t i, uint32_t value)
{
if (i < size)
{
@ -168,16 +168,16 @@ namespace pxt {
}
if (length <= i)
{
length = i + 1;
}
length = i + 1;
}
#ifdef DEBUG_BUILD
printf("In Segment::set\n");
this->print();
#endif
#endif
return;
}
}
uint16_t Segment::growthFactor(uint16_t size)
{
@ -201,12 +201,12 @@ namespace pxt {
growBy(max(minSize, growthFactor(size)));
}
void Segment::growBy(uint16_t newSize)
void Segment::growBy(uint16_t newSize)
{
#ifdef DEBUG_BUILD
printf("growBy: %d\n", newSize);
this->print();
#endif
#endif
if (size < newSize)
{
//this will throw if unable to allocate
@ -221,16 +221,16 @@ namespace pxt {
memset(tmp + size, Segment::DefaultValue, (newSize - size) * sizeof(uint32_t));
//free older segment;
::operator delete(data);
::operator delete(data);
data = tmp;
data = tmp;
size = newSize;
#ifdef DEBUG_BUILD
printf("growBy - after reallocation\n");
this->print();
#endif
#endif
}
//else { no shrinking yet; }
return;
@ -249,42 +249,42 @@ namespace pxt {
{
if (newLength > size)
{
ensure(length);
ensure(length);
}
length = newLength;
return;
}
void Segment::push(uint32_t value)
{
void Segment::push(uint32_t value)
{
this->set(length, value);
}
uint32_t Segment::pop()
uint32_t Segment::pop()
{
#ifdef DEBUG_BUILD
printf("In Segment::pop\n");
this->print();
#endif
#endif
if (length > 0)
{
--length;
uint32_t value = data[length];
data[length] = Segment::DefaultValue;
--length;
return value;
}
return Segment::DefaultValue;
}
//this function removes an element at index i and shifts the rest of the elements to
//left to fill the gap
uint32_t Segment::remove(uint32_t i)
//left to fill the gap
uint32_t Segment::remove(uint32_t i)
{
#ifdef DEBUG_BUILD
printf("In Segment::remove index:%u\n", i);
this->print();
#endif
#endif
if (i < length)
{
//value to return
@ -294,24 +294,24 @@ namespace pxt {
//Move the rest of the elements to fill in the gap.
memmove(data + i, data + i + 1, (length - i - 1) * sizeof(uint32_t));
}
length--;
data[length] = Segment::DefaultValue;
length--;
data[length] = Segment::DefaultValue;
#ifdef DEBUG_BUILD
printf("After Segment::remove index:%u\n", i);
this->print();
#endif
#endif
return ret;
}
return Segment::DefaultValue;
}
//this function inserts element value at index i by shifting the rest of the elements right.
void Segment::insert(uint32_t i, uint32_t value)
//this function inserts element value at index i by shifting the rest of the elements right.
void Segment::insert(uint32_t i, uint32_t value)
{
#ifdef DEBUG_BUILD
printf("In Segment::insert index:%u value:%u\n", i, value);
this->print();
#endif
#endif
if (i < length)
{
@ -322,7 +322,7 @@ namespace pxt {
memmove(data + i + 1, data + i, (length - i) * sizeof(uint32_t));
}
data[i] = value;
data[i] = value;
length++;
}
else
@ -333,7 +333,7 @@ namespace pxt {
#ifdef DEBUG_BUILD
printf("After Segment::insert index:%u\n", i);
this->print();
#endif
#endif
}
void Segment::print()
@ -360,29 +360,29 @@ namespace pxt {
#ifdef DEBUG_BUILD
printf("In Segment::destroy\n");
this->print();
#endif
#endif
length = size = 0;
::operator delete(data);
data = nullptr;
}
void RefCollection::push(uint32_t x)
void RefCollection::push(uint32_t x)
{
if (isRef()) incr(x);
head.push(x);
}
uint32_t RefCollection::pop()
uint32_t RefCollection::pop()
{
uint32_t ret = head.pop();
if (isRef())
{
incr(ret);
}
incr(ret);
}
return ret;
}
uint32_t RefCollection::getAt(int i)
uint32_t RefCollection::getAt(int i)
{
uint32_t tmp = head.get(i);
if (isRef())
@ -392,27 +392,24 @@ namespace pxt {
return tmp;
}
uint32_t RefCollection::removeAt(int i)
uint32_t RefCollection::removeAt(int i)
{
if (isRef())
{
decr(head.get(i));
}
// no decr() - we return the result
return head.remove(i);
}
void RefCollection::insertAt(int i, uint32_t value)
void RefCollection::insertAt(int i, uint32_t value)
{
head.insert(i, value);
if (isRef())
{
incr(value);
}
}
}
void RefCollection::setAt(int i, uint32_t value)
void RefCollection::setAt(int i, uint32_t value)
{
if (isRef())
if (isRef())
{
if (head.isValidIndex((uint32_t)i))
{
@ -423,9 +420,9 @@ namespace pxt {
head.set(i, value);
}
int RefCollection::indexOf(uint32_t x, int start)
int RefCollection::indexOf(uint32_t x, int start)
{
if (isString())
if (isString())
{
StringData *xx = (StringData*)x;
uint32_t i = start;
@ -443,8 +440,8 @@ namespace pxt {
}
i++;
}
}
else
}
else
{
uint32_t i = start;
while(head.isValidIndex(i))
@ -460,11 +457,12 @@ namespace pxt {
return -1;
}
int RefCollection::removeElement(uint32_t x)
int RefCollection::removeElement(uint32_t x)
{
int idx = indexOf(x, 0);
if (idx >= 0) {
removeAt(idx);
uint32_t elt = removeAt(idx);
if (isRef()) decr(elt);
return 1;
}
return 0;
@ -745,4 +743,4 @@ namespace pxt {
}
}
// vim: ts=2 sw=2 expandtab
// vim: ts=2 sw=2 expandtab

View File

@ -160,6 +160,7 @@ namespace pxt {
inline void unref()
{
//printf("DECR "); this->print();
check(refcnt > 0, ERR_REF_DELETED);
refcnt -= 2;
if (refcnt == 0) {
destroy();

View File

@ -27,6 +27,7 @@
"led.ts",
"motors.cpp",
"music.cpp",
"melodies.ts",
"music.ts",
"pins.cpp",
"pins.ts",
@ -47,7 +48,18 @@
"optionalConfig": {
"microbit-dal": {
"bluetooth": {
"enabled": 0
"private_addressing": 0,
"advertising_timeout": 0,
"tx_power": 6,
"dfu_service": 1,
"event_service": 1,
"device_info_service": 1,
"eddystone_url": 1,
"eddystone_uid": 1,
"open": 0,
"pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
}
}
}

236
libs/core/shims.d.ts vendored
View File

@ -56,7 +56,7 @@ declare interface Image {
* @param frameOffset x offset moved on each animation step, eg: 1, 2, 5
* @param interval time between each animation step in milli seconds, eg: 200
*/
//% help=images/show-image weight=79 async blockNamespace=images
//% help=images/scroll-image weight=79 async blockNamespace=images
//% blockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8
//% parts="ledmatrix" shim=ImageMethods::scrollImage
scrollImage(frameOffset: number, interval: number): void;
@ -152,11 +152,11 @@ declare namespace basic {
* @param leds the pattern of LED to turn on/off
* @param interval time in milliseconds to pause after drawing
*/
//% help=basic/show-leds
//% help=basic/show-leds
//% weight=95 blockGap=8
//% imageLiteral=1 async
//% blockId=device_show_leds
//% block="show leds"
//% block="show leds" icon="\uf00a"
//% parts="ledmatrix" interval.defl=400 shim=basic::showLeds
function showLeds(leds: string, interval?: number): void;
@ -165,9 +165,9 @@ declare namespace basic {
* @param text the text to scroll on the screen, eg: "Hello!"
* @param interval how fast to shift characters; eg: 150, 100, 200, -100
*/
//% help=basic/show-string
//% help=basic/show-string
//% weight=87 blockGap=8
//% block="show|string %text"
//% block="show|string %text"
//% async
//% blockId=device_print_message
//% parts="ledmatrix" interval.defl=150 shim=basic::showString
@ -178,7 +178,8 @@ declare namespace basic {
*/
//% help=basic/clear-screen weight=79
//% blockId=device_clear_display block="clear screen"
//% parts="ledmatrix" shim=basic::clearScreen
//% parts="ledmatrix"
//% advanced=true shim=basic::clearScreen
function clearScreen(): void;
/**
@ -202,8 +203,8 @@ declare namespace basic {
* 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=8
//% blockId=device_forever block="forever" shim=basic::forever
//% help=basic/forever weight=55 blockGap=8 blockAllowMultiple=1 afterOnStart=true
//% blockId=device_forever block="forever" icon="\uf01e" shim=basic::forever
function forever(a: () => void): void;
/**
@ -212,19 +213,19 @@ declare namespace basic {
*/
//% help=basic/pause weight=54
//% async block="pause (ms) %pause"
//% blockId=device_pause shim=basic::pause
//% blockId=device_pause icon="\uf110" shim=basic::pause
function pause(ms: number): void;
}
//% color=#C90072 weight=99 icon="\uf192"
//% color=#B4009E weight=99 icon="\uf192"
declare namespace input {
/**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
* @param button TODO
* @param body TODO
* Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button the button that needs to be pressed
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed"
@ -233,25 +234,27 @@ declare namespace input {
/**
* Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO
* @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/
//% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME"
//% parts="accelerometer" shim=input::onGesture
//% parts="accelerometer"
//% NAME.fieldEditor="gridpicker" NAME.fieldOptions.columns=4 shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void;
/**
* Do something when a pin is pressed.
* @param name the pin that needs to be pressed
* Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed" shim=input::onPinPressed
//% blockId=device_pin_event block="on pin %name|pressed" shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void;
/**
* Do something when a pin is released.
* @param name the pin that needs to be released
* @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=8
@ -261,6 +264,7 @@ declare namespace input {
/**
* Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/
//% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed"
@ -271,7 +275,7 @@ declare namespace input {
/**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch
* @param name pin used to detect the touch, eg: TouchPin.P0
*/
//% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed"
@ -335,16 +339,25 @@ declare namespace input {
/**
* Gets the number of milliseconds elapsed since power on.
*/
//% help=input/running-time weight=50
//% help=input/running-time weight=50 blockGap=8
//% blockId=device_get_running_time block="running time (ms)"
//% advanced=true shim=input::runningTime
function runningTime(): number;
/**
* 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 shim=input::runningTimeMicros
function runningTimeMicros(): number;
/**
* Obsolete, compass calibration is automatic.
*/
//% help=input/calibrate weight=0 shim=input::calibrate
function calibrate(): void;
//% help=input/calibrate-compass advanced=true
//% blockId="input_compass_calibrate" block="calibrate compass" shim=input::calibrateCompass
function calibrateCompass(): void;
/**
* Sets the accelerometer sample range in gravities.
@ -367,7 +380,7 @@ declare namespace control {
/**
* Schedules code that run in the background.
*/
//% help=control/in-background
//% help=control/in-background blockAllowMultiple=1 afterOnStart=true
//% blockId="control_in_background" block="run in background" blockGap=8 shim=control::inBackground
function inBackground(a: () => void): void;
@ -393,6 +406,7 @@ declare namespace control {
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
*/
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
//% help=control/raise-event
//% mode.defl=1 shim=control::raiseEvent
function raiseEvent(src: number, value: number, mode?: EventCreationMode): void;
@ -400,6 +414,7 @@ declare namespace control {
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1 shim=control::onEvent
function onEvent(src: number, value: number, handler: () => void): void;
@ -407,6 +422,7 @@ declare namespace control {
* Gets the value of the last event executed on the bus
*/
//% blockId=control_event_value" block="event value"
//% help=control/event-value
//% weight=18 shim=control::eventValue
function eventValue(): number;
@ -414,19 +430,22 @@ declare namespace control {
* Gets the timestamp of the last event executed on the bus
*/
//% blockId=control_event_timestamp" block="event timestamp"
//% help=control/event-timestamp
//% weight=19 blockGap=8 shim=control::eventTimestamp
function eventTimestamp(): number;
/**
* Gets a friendly name for the device derived from the its serial number
*/
//% blockId="control_device_name" block="device name" weight=10 blockGap=8 shim=control::deviceName
//% blockId="control_device_name" block="device name" weight=10 blockGap=8
//% advanced=true shim=control::deviceName
function deviceName(): string;
/**
* Derive a unique, consistent serial number of this device from internal data.
*/
//% blockId="control_device_serial_number" block="device serial number" weight=9 shim=control::deviceSerialNumber
//% blockId="control_device_serial_number" block="device serial number" weight=9
//% advanced=true shim=control::deviceSerialNumber
function deviceSerialNumber(): number;
}
@ -437,14 +456,28 @@ declare namespace led {
/**
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO
* @param y TODO
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
*/
//% help=led/plot weight=78
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::plot
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::plot
function plot(x: number, y: number): void;
/**
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x the horizontal coordinate of the LED starting at 0
* @param y the vertical coordinate of the LED starting at 0
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
*/
//% help=led/plot-brightness weight=78
//% blockId=device_plot_brightness block="plot|x %x|y %y|brightness %brightness" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
//% advanced=true shim=led::plotBrightness
function plotBrightness(x: number, y: number, brightness: number): void;
/**
* Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
* @param x TODO
@ -452,7 +485,8 @@ declare namespace led {
*/
//% help=led/unplot weight=77
//% blockId=device_unplot block="unplot|x %x|y %y" blockGap=8
//% parts="ledmatrix" shim=led::unplot
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::unplot
function unplot(x: number, y: number): void;
/**
@ -462,7 +496,8 @@ declare namespace led {
*/
//% help=led/point weight=76
//% blockId=device_point block="point|x %x|y %y"
//% parts="ledmatrix" shim=led::point
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::point
function point(x: number, y: number): boolean;
/**
@ -481,7 +516,8 @@ declare namespace led {
//% help=led/set-brightness weight=59
//% blockId=device_set_brightness block="set brightness %value"
//% parts="ledmatrix"
//% advanced=true shim=led::setBrightness
//% advanced=true
//% value.min=0 value.max=255 shim=led::setBrightness
function setBrightness(value: number): void;
/**
@ -501,10 +537,16 @@ declare namespace led {
//% parts="ledmatrix" advanced=true shim=led::setDisplayMode
function setDisplayMode(mode: DisplayMode): void;
/**
* Gets the current display mode
*/
//% weight=1 parts="ledmatrix" advanced=true shim=led::displayMode
function displayMode(): DisplayMode;
/**
* Turns on or off the display
*/
//% help=led/enable blockId=device_led_enable
//% help=led/enable blockId=device_led_enable block="led enable %on"
//% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void;
@ -552,90 +594,111 @@ declare namespace music {
* @param frequency pitch of the tone to play in Hertz (Hz)
* @param ms tone duration in milliseconds (ms)
*/
//% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8
//% parts="speaker" async useEnumVal=1 shim=music::playTone
function playTone(frequency: number, ms: number): void;
//%
//% parts="speaker" async useEnumVal=1 shim=music::speakerPlayTone
function speakerPlayTone(frequency: number, ms: number): void;
}
declare namespace pins {
/**
* Read the specified pin or connector as either 0 or 1
* @param name pin to read from
* @param name pin to read from, eg: DigitalPin.P0
*/
//% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 shim=pins::digitalReadPin
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" shim=pins::digitalReadPin
function digitalReadPin(name: DigitalPin): number;
/**
* Set a pin or connector value to either 0 or 1.
* @param name pin to write to
* @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0
*/
//% help=pins/digital-write-pin weight=29
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value" shim=pins::digitalWritePin
//% blockId=device_set_digital_pin block="digital write|pin %name|to %value"
//% value.min=0 value.max=1
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" shim=pins::digitalWritePin
function digitalWritePin(name: DigitalPin, value: number): void;
/**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to
* @param name pin to write to, eg: AnalogPin.P0
*/
//% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" shim=pins::analogReadPin
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogReadPin
function analogReadPin(name: AnalogPin): number;
/**
* Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to
* @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/
//% help=pins/analog-write-pin weight=24
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8 shim=pins::analogWritePin
//% blockId=device_set_analog_pin block="analog write|pin %name|to %value" blockGap=8
//% value.min=0 value.max=1023
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogWritePin
function analogWritePin(name: AnalogPin, value: number): void;
/**
* 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 name analog pin to set period to
* @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000
*/
//% help=pins/analog-set-period weight=23 blockGap=8
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros" shim=pins::analogSetPeriod
//% blockId=device_set_analog_period block="analog set period|pin %pin|to (µs)%micros"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" shim=pins::analogSetPeriod
function analogSetPeriod(name: AnalogPin, micros: number): void;
/**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/
//% help=pins/on-pulsed weight=22 blockGap=8
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed
//% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::onPulsed
function onPulsed(name: DigitalPin, pulse: PulseValue, body: () => void): void;
/**
* Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.
*/
//% help=pins/pulse-duration
//% help=pins/pulse-duration advanced=true
//% blockId=pins_pulse_duration block="pulse duration (µs)"
//% weight=21 blockGap=8 shim=pins::pulseDuration
function pulseDuration(): number;
/**
* Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse
* @param value the value of the pulse (default high)
* @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds
*/
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
//% weight=20 maxDuration.defl=2000000 shim=pins::pulseIn
//% weight=20 advanced=true
//% help=pins/pulse-in
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" name.fieldOptions.width="300" maxDuration.defl=2000000 shim=pins::pulseIn
function pulseIn(name: DigitalPin, value: PulseValue, maxDuration?: number): number;
/**
* 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 name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0
*/
//% help=pins/servo-write-pin weight=20
//% blockId=device_set_servo_pin block="servo write|pin %name|to %value" blockGap=8
//% parts=microservo trackArgs=0 shim=pins::servoWritePin
//% parts=microservo trackArgs=0
//% value.min=0 value.max=180
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::servoWritePin
function servoWritePin(name: AnalogPin, value: number): void;
/**
@ -644,21 +707,25 @@ declare namespace pins {
* @param micros pulse duration in micro seconds, eg:1500
*/
//% help=pins/servo-set-pulse weight=19
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros" shim=pins::servoSetPulse
//% blockId=device_set_servo_pulse block="servo set pulse|pin %value|to (µs) %micros"
//% value.fieldEditor="gridpicker" value.fieldOptions.columns=4
//% value.fieldOptions.tooltips="false" shim=pins::servoSetPulse
function servoSetPulse(name: AnalogPin, micros: number): void;
/**
* Sets the pin used when using `pins->analog pitch`.
* @param name TODO
* Sets the pin used when using `analog pitch` or music.
* @param name pin to modulate pitch from
*/
//% blockId=device_analog_set_pitch_pin block="analog set pitch pin %name"
//% help=pins/analog-set-pitch weight=3 advanced=true shim=pins::analogSetPitchPin
//% help=pins/analog-set-pitch-pin weight=3 advanced=true
//% name.fieldEditor="gridpicker" name.fieldOptions.columns=4
//% name.fieldOptions.tooltips="false" shim=pins::analogSetPitchPin
function analogSetPitchPin(name: AnalogPin): void;
/**
* 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
* @param frequency frequency to modulate in Hz.
* @param ms duration of the pitch in milli seconds.
*/
//% blockId=device_analog_pitch block="analog pitch %frequency|for (ms) %ms"
//% help=pins/analog-pitch weight=4 async advanced=true blockGap=8 shim=pins::analogPitch
@ -666,11 +733,13 @@ declare namespace pins {
/**
* Configures the pull of this pin.
* @param name pin to set the pull mode on
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone
* @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/
//% help=pins/set-pull weight=3
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull
//% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::setPull
function setPull(name: DigitalPin, pull: PinPullMode): void;
/**
@ -680,7 +749,9 @@ declare namespace pins {
* @param type the type of events for this pin to emit, eg: PinEventType.Edge
*/
//% help=pins/set-events weight=4 advanced=true
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events" shim=pins::setEvents
//% blockId=device_set_pin_events block="set pin %pin|to emit %type|events"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="300" shim=pins::setEvents
function setEvents(name: DigitalPin, type: PinEventType): void;
/**
@ -706,9 +777,40 @@ declare namespace pins {
* Write to the SPI slave and return the response
* @param value Data to be sent to the SPI slave
*/
//% help=pins/spi-write weight=5
//% help=pins/spi-write weight=5 advanced=true
//% blockId=spi_write block="spi write %value" shim=pins::spiWrite
function spiWrite(value: number): number;
/**
* Sets the SPI frequency
* @param frequency the clock frequency, eg: 1000000
*/
//% help=pins/spi-frequency weight=4 advanced=true
//% blockId=spi_frequency block="spi frequency %frequency" shim=pins::spiFrequency
function spiFrequency(frequency: number): void;
/**
* Sets the SPI bits and mode
* @param bits the number of bits, eg: 8
* @param mode the mode, eg: 3
*/
//% help=pins/spi-format weight=3 advanced=true
//% blockId=spi_format block="spi format|bits %bits|mode %mode" shim=pins::spiFormat
function spiFormat(bits: number, mode: number): void;
/**
* Sets the MOSI, MISO, SCK pins used by the SPI instance
*
*/
//% help=pins/spi-pins weight=2 advanced=true
//% blockId=spi_pins block="spi set pins|MOSI %mosi|MISO %miso|SCK %sck"
//% mosi.fieldEditor="gridpicker" mosi.fieldOptions.columns=4
//% mosi.fieldOptions.tooltips="false" mosi.fieldOptions.width="300"
//% miso.fieldEditor="gridpicker" miso.fieldOptions.columns=4
//% miso.fieldOptions.tooltips="false" miso.fieldOptions.width="300"
//% sck.fieldEditor="gridpicker" sck.fieldOptions.columns=4
//% sck.fieldOptions.tooltips="false" sck.fieldOptions.width="300" shim=pins::spiPins
function spiPins(mosi: DigitalPin, miso: DigitalPin, sck: DigitalPin): void;
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-calliope",
"version": "1.0.13",
"version": "1.0.18",
"description": "Calliope Mini editor for PXT",
"keywords": [
"JavaScript",
@ -36,7 +36,7 @@
"semantic-ui-less": "^2.2.4"
},
"dependencies": {
"pxt-core": "0.14.31"
"pxt-core": "0.14.32"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -24,6 +24,10 @@
"deployDrives": "MINI",
"driveName": "MINI",
"hexMimeType": "application/x-calliope-hex",
"openocdScript": "source [find interface/cmsis-dap.cfg]; source [find target/nrf51.cfg]",
"flashUsableEnd": 245760,
"flashEnd": 245760,
"flashCodeAlign": 1024,
"upgrades": [
{
"type": "package",
@ -54,11 +58,15 @@
"logicBlocks": true,
"variablesBlocks": true,
"textBlocks": true,
"listsBlocks": true,
"functionBlocks": true,
"onStartColor": "#54C9C9",
"onStartNamespace": "basic"
"onStartNamespace": "basic",
"onStartWeight": 54
},
"simulator": {
"autoRun": true,
"enableTrace": true,
"streams": true,
"aspectRatio": 1.13,
"parts": false,

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -286,6 +286,10 @@ namespace pxsim.led {
runtime.queueDisplayUpdate()
}
export function displayMode() : DisplayMode {
return board().ledMatrixState.displayMode;
}
export function screenshot(): Image {
let img = createImage(5)
board().ledMatrixState.image.copyTo(0, 5, img, 0);

View File

@ -7,7 +7,7 @@ namespace pxsim {
}
namespace pxsim.music {
export function playTone(frequency: number, ms: number) {
export function speakerPlayTone(frequency: number, ms: number) {
const b = board();
b.speakerState.frequency = frequency;
b.speakerState.ms = ms;

View File

@ -11,7 +11,12 @@
Blockly
*******************************/
.blocklyToolboxDiv {
padding:7px;
}
div.blocklyTreeRow {
border-radius:8px;
box-shadow: inset 0 -1px 0 0 #ecf0f1;
margin-bottom: 0px !important;
@ -29,15 +34,10 @@ span.blocklyTreeLabel {
}
.blocklyToolboxDiv, .monacoToolboxDiv {
background-color: white !important;
border-left: 1px solid #ecf0f1 !important;
box-shadow: 4px 0px 2px -4px rgba(0,0,0,0.12), 4px 0px 2px -4px rgba(0,0,0,0.24);
}
.blocklyFlyoutBackground {
fill: #525A67 !important;
}
/* Remove shadow around blockly blocks */
.blocklyPathDark, .blocklyPathLight {
display: none;

View File

@ -6,9 +6,6 @@
@fontName : 'Roboto Mono';
@emSize : 14px;
@fontSize : 13px;
/*-------------------
Site Colors
--------------------*/

View File

@ -47,31 +47,8 @@
width: 100%;
}
/*******************************
Blockly
*******************************/
div.blocklyTreeRow {
border-radius:8px;
}
/* This removes any padding at the top of the toolbox */
div.blocklyTreeRoot {
padding: 0px !important;
}
/* Blockly Text */
div.blocklyTreeLabel {
font-family: @pageFont !important;
font-size:1rem !important;
}
.blocklyFlyoutBackground {
fill: @grey;
}
.blocklyToolboxDiv {
padding:7px;
#downloadArea {
background: transparent !important;
}
.organization {
@ -85,8 +62,19 @@ div.blocklyTreeLabel {
}
}
/* Mobile */
@media only screen and (max-width: @largestMobileScreen) {
#filelist {
background: transparent !important;
}
}
/* Tablet */
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
#filelist {
background: transparent !important;
}
}
/* Small Monitor */
@ -96,15 +84,3 @@ div.blocklyTreeLabel {
/* Large Monitor */
@media only screen and (min-width: @largeMonitorBreakpoint) {
}
/*******************************
Menu Bar
*******************************/
#menubar {
height: 5rem;
}
#fileNameInput {
width: 350px;
}

View File

@ -43,16 +43,16 @@
@form : 'default';
@grid : 'pxt';
@menu : 'pxt';
@message : 'default';
@message : 'pxt';
@table : 'default';
/* Modules */
@accordion : 'default';
@checkbox : 'default';
@dimmer : 'default';
@dimmer : 'pxt';
@dropdown : 'default';
@embed : 'default';
@modal : 'default';
@modal : 'pxt';
@nag : 'default';
@popup : 'default';
@progress : 'default';
@ -66,7 +66,7 @@
/* Views */
@ad : 'default';
@card : 'default';
@card : 'pxt';
@comment : 'default';
@feed : 'default';
@item : 'default';
@ -91,5 +91,9 @@
@fontPath : 'fonts';
/*
@headerFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
@pageFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
*/
/* End Config */