Use field toggle for switching the motor on / off

This commit is contained in:
Sam El-Husseini 2017-10-04 17:04:26 -04:00
parent b18b8333d0
commit 6a719e7718
5 changed files with 25 additions and 2 deletions

View File

@ -70,7 +70,7 @@ declare namespace loops {
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=loops/forever weight=100 blockGap=8
//% help=loops/forever weight=100
//% blockId=forever block="forever" blockAllowMultiple=1 shim=loops::forever
function forever(a: () => void): void;

View File

@ -37,6 +37,9 @@
"output.start|param|out": "the output connection that the motor is connected to",
"output.stop": "Turn motor off.",
"output.stop|param|out": "the output connection that the motor is connected to",
"output.switchMotor": "Switch the motor on or off.",
"output.switchMotor|param|on": "1 to turn the motor on, 0 to turn it off",
"output.switchMotor|param|out": "the output connection that the motor is connected to",
"output.turn": "Turn a motor on for a specified number of milliseconds.",
"output.turn|param|ms": "the number of milliseconds to turn the motor on, eg: 500",
"output.turn|param|out": "the output connection that the motor is connected to",

View File

@ -33,6 +33,7 @@
"output.setSpeed|block": "set motor %out| speed to %speed",
"output.start|block": "turn motor %out|on",
"output.stop|block": "turn motor %out|off",
"output.switchMotor|block": "turn motor %out|%on",
"output.turn|block": "turn motor %out| on for %ms|milliseconds",
"output|block": "output",
"screen.drawText|block": "print %text| at x: %x| y: %y",

View File

@ -81,12 +81,30 @@ namespace output {
})
}
/**
* Switch the motor on or off.
* @param out the output connection that the motor is connected to
* @param on 1 to turn the motor on, 0 to turn it off
*/
//% blockId=output_switch block="turn motor %out|%on"
//% weight=90 group="Motors"
//% on.fieldEditor="toggle"
export function switchMotor(out: Output, on: number, useBrake = false) {
if (on == 0) {
output.stop(out, useBrake);
} else {
output.start(out);
}
}
/**
* Turn motor off.
* @param out the output connection that the motor is connected to
*/
//% blockId=output_stop block="turn motor %out|off"
//% weight=90 group="Motors"
//% deprecated=1
export function stop(out: Output, useBrake = false) {
let b = mkCmd(out, DAL.opOutputStop, 1)
b.setNumber(NumberFormat.UInt8LE, 2, useBrake ? 1 : 0)
@ -99,6 +117,7 @@ namespace output {
*/
//% blockId=output_start block="turn motor %out|on"
//% weight=95 group="Motors"
//% deprecated=1
export function start(out: Output) {
if (currentSpeed[out] == -1) setSpeed(out, 50)
let b = mkCmd(out, DAL.opOutputStart, 0)

View File

@ -119,7 +119,7 @@
@editorToolsBackground: #fcfbfa;
@blocklySvgColor: #ecf6ff;
@homeScreenBackground: #f4f7f9;
@homeScreenBackground: #EAEEEF;
/*-------------------
Full screen