Merge branch 'master' of github.com:Microsoft/pxt-ev3

This commit is contained in:
Michal Moskal 2017-10-27 15:17:24 +01:00
commit c0bab4877a
14 changed files with 221 additions and 89 deletions

View File

@ -14,6 +14,34 @@ These six activities require the LEGO® MINDSTORMS® Education EV3 Core Set (455
"url":"/maker/sound-machine", "url":"/maker/sound-machine",
"cardType": "example", "cardType": "example",
"imageUrl": "/static/maker/sound-machine.png" "imageUrl": "/static/maker/sound-machine.png"
},
{
"name": "Sound Of Color",
"description": "Play different sounds based on the color",
"url":"/maker/sound-of-color",
"cardType": "example",
"imageUrl": "/static/maker/sound-of-color.png"
},
{
"name": "Security Gadget",
"description": "Raise the alarm when your brick is lifted!",
"url":"/maker/security-gadget",
"cardType": "example",
"imageUrl": "/static/maker/security-gadget.png"
},
{
"name": "Intruder Detector",
"description": "Raise the alarm when an intruder sneaks in",
"url":"/maker/intruder-detector",
"cardType": "example",
"imageUrl": "/static/maker/intruder-detector.png"
},
{
"name": "Puppet",
"description": "Build an automated puppet",
"url":"/maker/puppet",
"cardType": "example",
"imageUrl": "/static/maker/puppet.png"
} }
] ]
``` ```

View File

@ -0,0 +1,11 @@
# Intruder Detector
This program will activate an alarm when an object moves in front of the Ultrasonic Sensor.
TODO support for event when value changes
```blocks
input.ultrasonic4.onObjectNear(function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
})
```

17
docs/maker/puppet.md Normal file
View File

@ -0,0 +1,17 @@
# Puppet
Use this program with the Programmable Brick and Large Motor.
```blocks
loops.forever(function () {
output.largeMotorA.setPower(30)
output.largeMotorA.on(true)
loops.pause(100)
output.largeMotorA.on(false)
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
output.largeMotorA.setPower(-30)
output.largeMotorA.on(true)
loops.pause(100)
output.largeMotorA.on(false)
})
```

View File

@ -0,0 +1,9 @@
# Security Gadget
This program will activate an alarm when an object is lifted from the Touch Sensor.
```blocks
input.touchSensor1.onEvent(TouchSensorEvent.Released, function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
})
```

View File

@ -0,0 +1,15 @@
# Sound Of Color
This program will play different sounds when the wheel is rotated. The sound is determined by which color is placed in front of the color Sensor.
```blocks
input.color3.onColorDetected(ColorSensorColor.Blue, function () {
music.playTone(Note.G4, music.beat(BeatFraction.Half))
})
input.color3.onColorDetected(ColorSensorColor.Red, function () {
music.playTone(Note.C5, music.beat(BeatFraction.Half))
})
input.color3.onColorDetected(ColorSensorColor.Green, function () {
music.playTone(Note.D5, music.beat(BeatFraction.Half))
})
```

BIN
docs/static/maker/intruder-detector.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
docs/static/maker/puppet.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 KiB

BIN
docs/static/maker/security-gadget.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 KiB

After

Width:  |  Height:  |  Size: 141 KiB

BIN
docs/static/maker/sound-of-color.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

View File

@ -56,22 +56,24 @@
"input.remoteButtonCenter": "Remote beacon (center) button.", "input.remoteButtonCenter": "Remote beacon (center) button.",
"input.remoteButtonTopLeft": "Remote top-left button.", "input.remoteButtonTopLeft": "Remote top-left button.",
"input.remoteButtonTopRight": "Remote top-right button.", "input.remoteButtonTopRight": "Remote top-right button.",
"output.Motor.off": "Power off the motor.", "output.Motor.clearCount": "Clears the motor count",
"output.Motor.on": "Power on the motor.", "output.Motor.count": "Gets motor step count.",
"output.Motor.onForTime": "Power on the motor for a specified number of milliseconds.", "output.Motor.on": "Power on or off the motor.",
"output.Motor.onForTime|param|brake": "whether or not to use the brake", "output.Motor.reset": "Resets the motor.",
"output.Motor.onForTime|param|ms": "the number of milliseconds to turn the motor on, eg: 500", "output.Motor.setBrake": "Sets the automatic brake on or off when the motor is off",
"output.Motor.onForTime|param|power": "the motor power level from ``-100`` to ``100``, eg: 50", "output.Motor.setBrake|param|brake": "a value indicating if the motor should break when off",
"output.Motor.on|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
"output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.", "output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.",
"output.Motor.setPower|param|power": "the desired speed to use. eg: 50", "output.Motor.setPower|param|power": "the desired speed to use. eg: 50",
"output.Motor.setReversed": "Reverses the motor polarity",
"output.Motor.speed": "Gets motor actual speed.", "output.Motor.speed": "Gets motor actual speed.",
"output.Motor.tachoCount": "Gets motor tacho count.",
"output.createBuffer": "Create a new zero-initialized buffer.", "output.createBuffer": "Create a new zero-initialized buffer.",
"output.createBuffer|param|size": "number of bytes in the buffer", "output.createBuffer|param|size": "number of bytes in the buffer",
"output.pattern": "Pattern block.", "output.pattern": "Pattern block.",
"output.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", "output.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
"output.setStatusLight": "Set lights.", "output.setStatusLight": "Set lights.",
"output.setStatusLight|param|pattern": "the lights pattern to use.", "output.setStatusLight|param|pattern": "the lights pattern to use.",
"output.stopAllMotors": "Stops all motors",
"screen.clear": "Clear screen and reset font to normal.", "screen.clear": "Clear screen and reset font to normal.",
"screen.doubleIcon": "Double size of an icon.", "screen.doubleIcon": "Double size of an icon.",
"screen.drawIcon": "Draw an icon on the screen.", "screen.drawIcon": "Draw an icon on the screen.",

View File

@ -82,17 +82,24 @@
"input.ultrasonic3|block": "ultrasonic sensor 3", "input.ultrasonic3|block": "ultrasonic sensor 3",
"input.ultrasonic4|block": "ultrasonic sensor 4", "input.ultrasonic4|block": "ultrasonic sensor 4",
"input|block": "input", "input|block": "input",
"output.Motor.off|block": "%motor|OFF then brake %brake", "output.Motor.count|block": "%motor|count",
"output.Motor.onForTime|block": "%motor|ON at power %power|for %ms=timePicker|ms then brake %brake", "output.Motor.on|block": "%motor|%onOrOff",
"output.Motor.on|block": "%motor|ON at power %power", "output.Motor.setBrake|block": "%motor|set brake %brake",
"output.Motor.setPower|block": "%motor|set power to %speed", "output.Motor.setPower|block": "%motor|set power to %speed",
"output.Motor.setReversed|block": "%motor|set reversed %reversed",
"output.Motor.speed|block": "%motor|speed", "output.Motor.speed|block": "%motor|speed",
"output.motorA|block": "motor A", "output.Motor.tachoCount|block": "%motor|tacho count",
"output.motorB|block": "motor B", "output.largeMotorA|block": "large motor A",
"output.motorC|block": "motor C", "output.largeMotorB|block": "large motor B",
"output.motorD|block": "motor D", "output.largeMotorC|block": "large motor C",
"output.largeMotorD|block": "large motor D",
"output.mediumMotorA|block": "medium motor A",
"output.mediumMotorB|block": "medium motor B",
"output.mediumMotorC|block": "medium motor C",
"output.mediumMotorD|block": "medium motor D",
"output.pattern|block": "%pattern", "output.pattern|block": "%pattern",
"output.setStatusLight|block": "set status light %pattern=led_pattern", "output.setStatusLight|block": "set status light %pattern=led_pattern",
"output.stopAllMotors|block": "stop all motors",
"output|block": "output", "output|block": "output",
"screen.print|block": "print %text| at x: %x| y: %y", "screen.print|block": "print %text| at x: %x| y: %y",
"screen.setPixel|block": "set pixel %on| at x: %x| y: %y", "screen.setPixel|block": "set pixel %on| at x: %x| y: %y",

View File

@ -63,62 +63,46 @@ namespace output {
reset(Output.ALL) reset(Output.ALL)
} }
//% fixedInstances
export class Motor extends control.Component {
port: Output;
constructor(port: Output) {
super();
this.port = port;
}
/** /**
* Power off the motor. * Stops all motors
* @param motor the motor to turn off
*/ */
//% blockId=outputMotorOf block="%motor|OFF then brake %brake" //% blockId=motorStopAll block="stop all motors"
//% brake.fieldEditor=toggleonoff //% weight=10 group="Motors" blockGap=8
//% weight=100 group="Motors" blockGap=8 export function stopAllMotors() {
off(brake = false) { const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
const b = mkCmd(this.port, DAL.opOutputStop, 1)
b.setNumber(NumberFormat.UInt8LE, 2, brake ? 1 : 0)
writePWM(b) writePWM(b)
} }
/** //% fixedInstances
* Power on the motor. export class Motor extends control.Component {
* @param motor the motor to turn on private port: Output;
* @param power the motor power level from ``-100`` to ``100``, eg: 50 private large: boolean;
*/ private brake: boolean;
//% blockId=outputMotorOn block="%motor|ON at power %power"
//% power.min=-100 power.max=100 constructor(port: Output, large: boolean) {
//% weight=99 group="Motors" blockGap=8 super();
on(power: number = 50) { this.port = port;
this.setPower(power); this.large = large;
const b = mkCmd(this.port, DAL.opOutputStart, 0) this.brake = false;
writePWM(b);
} }
/** /**
* Power on the motor for a specified number of milliseconds. * Power on or off the motor.
* @param motor the motor to turn on * @param motor the motor to turn on
* @param power the motor power level from ``-100`` to ``100``, eg: 50 * @param power the motor power level from ``-100`` to ``100``, eg: 50
* @param ms the number of milliseconds to turn the motor on, eg: 500
* @param brake whether or not to use the brake
*/ */
//% blockId=outputMotorOnForTime block="%motor|ON at power %power|for %ms=timePicker|ms then brake %brake" //% blockId=outputMotorOn block="%motor|%onOrOff"
//% power.min=-100 power.max=100 //% onOrOff.fieldEditor=toggleonoff
//% brake.fieldEditor=toggleonoff //% weight=99 group="Motors" blockGap=8
//% weight=98 group="Motors" blockGap=8 on(onOrOff: boolean = true) {
onForTime(power: number, ms: number, brake = false) { if (onOrOff) {
step(this.port, { const b = mkCmd(this.port, DAL.opOutputStart, 0)
power, writePWM(b);
step1: 0, } else {
step2: ms, const b = mkCmd(this.port, DAL.opOutputStop, 1)
step3: 0, b.setNumber(NumberFormat.UInt8LE, 2, this.brake ? 1 : 0)
useSteps: false, writePWM(b)
useBrake: brake }
})
loops.pause(ms);
} }
/** /**
@ -127,7 +111,7 @@ namespace output {
* @param power the desired speed to use. eg: 50 * @param power the desired speed to use. eg: 50
*/ */
//% blockId=motorSetPower block="%motor|set power to %speed" //% blockId=motorSetPower block="%motor|set power to %speed"
//% weight=60 group="Motors" //% weight=62 group="Motors" blockGap=8
//% speed.min=-100 speed.max=100 //% speed.min=-100 speed.max=100
setPower(power: number) { setPower(power: number) {
const b = mkCmd(this.port, DAL.opOutputPower, 1) const b = mkCmd(this.port, DAL.opOutputPower, 1)
@ -135,44 +119,109 @@ namespace output {
writePWM(b) writePWM(b)
} }
/**
* Sets the automatic brake on or off when the motor is off
* @param brake a value indicating if the motor should break when off
*/
//% blockId=outputMotorSetBrakeMode block="%motor|set brake %brake"
//% brake.fieldEditor=toggleonoff
//% weight=60 group="Motors" blockGap=8
setBrake(brake: boolean) {
this.brake = brake;
}
/**
* Reverses the motor polarity
*/
//% blockId=motorSetReversed block="%motor|set reversed %reversed"
//% reversed.fieldEditor=toggleonoff
//% weight=59 group="Motors"
setReversed(reversed: boolean) {
const b = mkCmd(this.port, DAL.opOutputPolarity, 1)
b.setNumber(NumberFormat.Int8LE, 2, reversed ? -1 : 1);
writePWM(b)
}
/** /**
* Gets motor actual speed. * Gets motor actual speed.
* @param motor the port which connects to the motor * @param motor the port which connects to the motor
*/ */
//% blockId=motorSpeed block="%motor|speed" //% blockId=motorSpeed block="%motor|speed"
//% weight=50 group="Motors" blockGap=8 //% weight=50 group="Motors" blockGap=8
speed() { speed(): number {
return getMotorData(this.port).actualSpeed; return getMotorData(this.port).actualSpeed;
} }
/**
* Gets motor step count.
* @param motor the port which connects to the motor
*/
//% blockId=motorCount block="%motor|count"
//% weight=49 group="Motors" blockGap=8
count(): number {
return getMotorData(this.port).count;
} }
//% whenUsed fixedInstance block="motor B" /**
export const motorB = new Motor(Output.B); * Gets motor tacho count.
* @param motor the port which connects to the motor
*/
//% blockId=motorTachoCount block="%motor|tacho count"
//% weight=48 group="Motors"
tachoCount(): number {
return getMotorData(this.port).tachoCount;
}
//% whenUsed fixedInstance block="motor C" /**
export const motorC = new Motor(Output.C); * Clears the motor count
*/
clearCount() {
const b = mkCmd(this.port, DAL.opOutputClearCount, 0)
writePWM(b)
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (this.port & (1 << i)) {
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
}
}
}
//% whenUsed fixedInstance block="motor A" /**
export const motorA = new Motor(Output.A); * Resets the motor.
*/
reset() {
reset(this.port);
}
}
//% whenUsed fixedInstance block="motor D" //% whenUsed fixedInstance block="large motor A"
export const motorD = new Motor(Output.D); export const largeMotorA = new Motor(Output.A, true);
//% whenUsed fixedInstance block="large motor B"
export const largeMotorB = new Motor(Output.B, true);
//% whenUsed fixedInstance block="large motor C"
export const largeMotorC = new Motor(Output.C, true);
//% whenUsed fixedInstance block="large motor D"
export const largeMotorD = new Motor(Output.D, true);
//% whenUsed fixedInstance block="medium motor A"
export const mediumMotorA = new Motor(Output.A, false);
//% whenUsed fixedInstance block="medium motor B"
export const mediumMotorB = new Motor(Output.B, false);
//% whenUsed fixedInstance block="medium motor C"
export const mediumMotorC = new Motor(Output.C, false);
//% whenUsed fixedInstance block="medium motor D"
export const mediumMotorD = new Motor(Output.D, false);
function reset(out: Output) { function reset(out: Output) {
let b = mkCmd(out, DAL.opOutputReset, 0) let b = mkCmd(out, DAL.opOutputReset, 0)
writePWM(b) writePWM(b)
} }
function clearCount(out: Output) {
let b = mkCmd(out, DAL.opOutputClearCount, 0)
writePWM(b)
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (out & (1 << i)) {
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
}
}
}
function outOffset(out: Output) { function outOffset(out: Output) {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (out & (1 << i)) if (out & (1 << i))
@ -197,12 +246,6 @@ namespace output {
} }
} }
function setPolarity(out: Output, polarity: number) {
let b = mkCmd(out, DAL.opOutputPolarity, 1)
b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-1, 1, polarity))
writePWM(b)
}
interface StepOptions { interface StepOptions {
power?: number; power?: number;
speed?: number; // either speed or power has to be present speed?: number; // either speed or power has to be present

View File

@ -43,7 +43,7 @@ namespace input {
//% blockNamespace=input //% blockNamespace=input
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
onObjectNear(distance: number, handler: () => void) { onObjectNear(handler: () => void) {
control.onEvent(this._id, PromixityEvent.ObjectNear, handler); control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
if (this.distance() == PromixityEvent.ObjectNear) if (this.distance() == PromixityEvent.ObjectNear)
control.runInBackground(handler); control.runInBackground(handler);