Merge branch 'master' of github.com:Microsoft/pxt-ev3
This commit is contained in:
		@@ -14,6 +14,34 @@ These six activities require the LEGO® MINDSTORMS® Education EV3 Core Set (455
 | 
			
		||||
  "url":"/maker/sound-machine",
 | 
			
		||||
  "cardType": "example",
 | 
			
		||||
  "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"
 | 
			
		||||
}
 | 
			
		||||
]
 | 
			
		||||
```
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								docs/maker/intruder-detector.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								docs/maker/intruder-detector.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										17
									
								
								docs/maker/puppet.md
									
									
									
									
									
										Normal 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)
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										9
									
								
								docs/maker/security-gadget.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								docs/maker/security-gadget.md
									
									
									
									
									
										Normal 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))
 | 
			
		||||
})
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										15
									
								
								docs/maker/sound-of-color.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								docs/maker/sound-of-color.md
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										
											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
									
								
							
							
						
						
									
										
											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
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/maker/security-gadget.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 38 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/static/maker/sound-machine.png
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/maker/sound-machine.png
									
									
									
									
										vendored
									
									
								
							
										
											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
									
								
							
							
						
						
									
										
											BIN
										
									
								
								docs/static/maker/sound-of-color.png
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 159 KiB  | 
@@ -56,22 +56,24 @@
 | 
			
		||||
  "input.remoteButtonCenter": "Remote beacon (center) button.",
 | 
			
		||||
  "input.remoteButtonTopLeft": "Remote top-left button.",
 | 
			
		||||
  "input.remoteButtonTopRight": "Remote top-right button.",
 | 
			
		||||
  "output.Motor.off": "Power off the motor.",
 | 
			
		||||
  "output.Motor.on": "Power on the motor.",
 | 
			
		||||
  "output.Motor.onForTime": "Power on the motor for a specified number of milliseconds.",
 | 
			
		||||
  "output.Motor.onForTime|param|brake": "whether or not to use the brake",
 | 
			
		||||
  "output.Motor.onForTime|param|ms": "the number of milliseconds to turn the motor on, eg: 500",
 | 
			
		||||
  "output.Motor.onForTime|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
 | 
			
		||||
  "output.Motor.on|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
 | 
			
		||||
  "output.Motor.clearCount": "Clears the motor count",
 | 
			
		||||
  "output.Motor.count": "Gets motor step count.",
 | 
			
		||||
  "output.Motor.on": "Power on or off the motor.",
 | 
			
		||||
  "output.Motor.reset": "Resets the motor.",
 | 
			
		||||
  "output.Motor.setBrake": "Sets the automatic brake on or off when the motor is off",
 | 
			
		||||
  "output.Motor.setBrake|param|brake": "a value indicating if the motor should break when off",
 | 
			
		||||
  "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.setReversed": "Reverses the motor polarity",
 | 
			
		||||
  "output.Motor.speed": "Gets motor actual speed.",
 | 
			
		||||
  "output.Motor.tachoCount": "Gets motor tacho count.",
 | 
			
		||||
  "output.createBuffer": "Create a new zero-initialized buffer.",
 | 
			
		||||
  "output.createBuffer|param|size": "number of bytes in the buffer",
 | 
			
		||||
  "output.pattern": "Pattern block.",
 | 
			
		||||
  "output.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
 | 
			
		||||
  "output.setStatusLight": "Set lights.",
 | 
			
		||||
  "output.setStatusLight|param|pattern": "the lights pattern to use.",
 | 
			
		||||
  "output.stopAllMotors": "Stops all motors",
 | 
			
		||||
  "screen.clear": "Clear screen and reset font to normal.",
 | 
			
		||||
  "screen.doubleIcon": "Double size of an icon.",
 | 
			
		||||
  "screen.drawIcon": "Draw an icon on the screen.",
 | 
			
		||||
 
 | 
			
		||||
@@ -82,17 +82,24 @@
 | 
			
		||||
  "input.ultrasonic3|block": "ultrasonic sensor 3",
 | 
			
		||||
  "input.ultrasonic4|block": "ultrasonic sensor 4",
 | 
			
		||||
  "input|block": "input",
 | 
			
		||||
  "output.Motor.off|block": "%motor|OFF then brake %brake",
 | 
			
		||||
  "output.Motor.onForTime|block": "%motor|ON at power %power|for %ms=timePicker|ms then brake %brake",
 | 
			
		||||
  "output.Motor.on|block": "%motor|ON at power %power",
 | 
			
		||||
  "output.Motor.count|block": "%motor|count",
 | 
			
		||||
  "output.Motor.on|block": "%motor|%onOrOff",
 | 
			
		||||
  "output.Motor.setBrake|block": "%motor|set brake %brake",
 | 
			
		||||
  "output.Motor.setPower|block": "%motor|set power to %speed",
 | 
			
		||||
  "output.Motor.setReversed|block": "%motor|set reversed %reversed",
 | 
			
		||||
  "output.Motor.speed|block": "%motor|speed",
 | 
			
		||||
  "output.motorA|block": "motor A",
 | 
			
		||||
  "output.motorB|block": "motor B",
 | 
			
		||||
  "output.motorC|block": "motor C",
 | 
			
		||||
  "output.motorD|block": "motor D",
 | 
			
		||||
  "output.Motor.tachoCount|block": "%motor|tacho count",
 | 
			
		||||
  "output.largeMotorA|block": "large motor A",
 | 
			
		||||
  "output.largeMotorB|block": "large motor B",
 | 
			
		||||
  "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.setStatusLight|block": "set status light %pattern=led_pattern",
 | 
			
		||||
  "output.stopAllMotors|block": "stop all motors",
 | 
			
		||||
  "output|block": "output",
 | 
			
		||||
  "screen.print|block": "print %text| at x: %x| y: %y",
 | 
			
		||||
  "screen.setPixel|block": "set pixel %on| at x: %x| y: %y",
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ namespace output {
 | 
			
		||||
        buf[0] = DAL.opProgramStart
 | 
			
		||||
        writePWM(buf)
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    function writePWM(buf: Buffer): void {
 | 
			
		||||
        init()
 | 
			
		||||
        pwmMM.write(buf)
 | 
			
		||||
@@ -61,64 +61,48 @@ namespace output {
 | 
			
		||||
 | 
			
		||||
    function resetMotors() {
 | 
			
		||||
        reset(Output.ALL)
 | 
			
		||||
    }    
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Stops all motors
 | 
			
		||||
     */
 | 
			
		||||
    //% blockId=motorStopAll block="stop all motors"
 | 
			
		||||
    //% weight=10 group="Motors" blockGap=8
 | 
			
		||||
    export function stopAllMotors() {
 | 
			
		||||
        const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
 | 
			
		||||
        writePWM(b)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% fixedInstances
 | 
			
		||||
    export class Motor extends control.Component {
 | 
			
		||||
        port: Output;
 | 
			
		||||
        constructor(port: Output) {
 | 
			
		||||
        private port: Output;
 | 
			
		||||
        private large: boolean;
 | 
			
		||||
        private brake: boolean;
 | 
			
		||||
 | 
			
		||||
        constructor(port: Output, large: boolean) {
 | 
			
		||||
            super();
 | 
			
		||||
            this.port = port;
 | 
			
		||||
            this.large = large;
 | 
			
		||||
            this.brake = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Power off the motor.
 | 
			
		||||
         * @param motor the motor to turn off
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=outputMotorOf block="%motor|OFF then brake %brake"
 | 
			
		||||
        //% brake.fieldEditor=toggleonoff
 | 
			
		||||
        //% weight=100 group="Motors" blockGap=8
 | 
			
		||||
        off(brake = false) {
 | 
			
		||||
            const b = mkCmd(this.port, DAL.opOutputStop, 1)
 | 
			
		||||
            b.setNumber(NumberFormat.UInt8LE, 2, brake ? 1 : 0)
 | 
			
		||||
            writePWM(b)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Power on the motor.
 | 
			
		||||
         * Power on or off the motor.
 | 
			
		||||
         * @param motor the motor to turn on
 | 
			
		||||
         * @param power the motor power level from ``-100`` to ``100``, eg: 50
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=outputMotorOn block="%motor|ON at power %power"
 | 
			
		||||
        //% power.min=-100 power.max=100 
 | 
			
		||||
        //% blockId=outputMotorOn block="%motor|%onOrOff"
 | 
			
		||||
        //% onOrOff.fieldEditor=toggleonoff
 | 
			
		||||
        //% weight=99 group="Motors" blockGap=8
 | 
			
		||||
        on(power: number = 50) {
 | 
			
		||||
            this.setPower(power);
 | 
			
		||||
            const b = mkCmd(this.port, DAL.opOutputStart, 0)
 | 
			
		||||
            writePWM(b);                
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Power on the motor for a specified number of milliseconds.
 | 
			
		||||
         * @param motor the motor to turn on
 | 
			
		||||
         * @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"
 | 
			
		||||
        //% power.min=-100 power.max=100 
 | 
			
		||||
        //% brake.fieldEditor=toggleonoff
 | 
			
		||||
        //% weight=98 group="Motors" blockGap=8
 | 
			
		||||
        onForTime(power: number, ms: number, brake = false) {
 | 
			
		||||
            step(this.port, {
 | 
			
		||||
                power,
 | 
			
		||||
                step1: 0,
 | 
			
		||||
                step2: ms,
 | 
			
		||||
                step3: 0,
 | 
			
		||||
                useSteps: false,
 | 
			
		||||
                useBrake: brake
 | 
			
		||||
            })
 | 
			
		||||
            loops.pause(ms);
 | 
			
		||||
        on(onOrOff: boolean = true) {
 | 
			
		||||
            if (onOrOff) {
 | 
			
		||||
                const b = mkCmd(this.port, DAL.opOutputStart, 0)
 | 
			
		||||
                writePWM(b);
 | 
			
		||||
            } else {
 | 
			
		||||
                const b = mkCmd(this.port, DAL.opOutputStop, 1)
 | 
			
		||||
                b.setNumber(NumberFormat.UInt8LE, 2, this.brake ? 1 : 0)
 | 
			
		||||
                writePWM(b)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
@@ -127,7 +111,7 @@ namespace output {
 | 
			
		||||
         * @param power the desired speed to use. eg: 50
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=motorSetPower block="%motor|set power to %speed"
 | 
			
		||||
        //% weight=60 group="Motors"
 | 
			
		||||
        //% weight=62 group="Motors" blockGap=8
 | 
			
		||||
        //% speed.min=-100 speed.max=100
 | 
			
		||||
        setPower(power: number) {
 | 
			
		||||
            const b = mkCmd(this.port, DAL.opOutputPower, 1)
 | 
			
		||||
@@ -135,44 +119,109 @@ namespace output {
 | 
			
		||||
            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.
 | 
			
		||||
         * @param motor the port which connects to the motor
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=motorSpeed block="%motor|speed"
 | 
			
		||||
        //% weight=50 group="Motors" blockGap=8
 | 
			
		||||
        speed() {
 | 
			
		||||
        speed(): number {
 | 
			
		||||
            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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * 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)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Resets the motor.
 | 
			
		||||
         */
 | 
			
		||||
        reset() {
 | 
			
		||||
            reset(this.port);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% whenUsed fixedInstance block="motor B"
 | 
			
		||||
    export const motorB = new Motor(Output.B);
 | 
			
		||||
    //% whenUsed fixedInstance block="large motor A"
 | 
			
		||||
    export const largeMotorA = new Motor(Output.A, true);
 | 
			
		||||
 | 
			
		||||
    //% whenUsed fixedInstance block="motor C"
 | 
			
		||||
    export const motorC = new Motor(Output.C);
 | 
			
		||||
    //% whenUsed fixedInstance block="large motor B"
 | 
			
		||||
    export const largeMotorB = new Motor(Output.B, true);
 | 
			
		||||
 | 
			
		||||
    //% whenUsed fixedInstance block="motor A"
 | 
			
		||||
    export const motorA = new Motor(Output.A);
 | 
			
		||||
    //% whenUsed fixedInstance block="large motor C"
 | 
			
		||||
    export const largeMotorC = new Motor(Output.C, true);
 | 
			
		||||
 | 
			
		||||
    //% whenUsed fixedInstance block="motor D"
 | 
			
		||||
    export const motorD = new Motor(Output.D);
 | 
			
		||||
    //% 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) {
 | 
			
		||||
        let b = mkCmd(out, DAL.opOutputReset, 0)
 | 
			
		||||
        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) {
 | 
			
		||||
        for (let i = 0; i < DAL.NUM_OUTPUTS; ++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 {
 | 
			
		||||
        power?: number;
 | 
			
		||||
        speed?: number; // either speed or power has to be present
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,7 @@ namespace input {
 | 
			
		||||
        //% blockNamespace=input
 | 
			
		||||
        //% weight=100 blockGap=8
 | 
			
		||||
        //% group="Ultrasonic Sensor"
 | 
			
		||||
        onObjectNear(distance: number, handler: () => void) {
 | 
			
		||||
        onObjectNear(handler: () => void) {
 | 
			
		||||
            control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
 | 
			
		||||
            if (this.distance() == PromixityEvent.ObjectNear)
 | 
			
		||||
                control.runInBackground(handler);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user