Thresholds (#222)

* add threshold blocks

* updated strings

* added gap

* reorg color/gyro blocks

* fixing sound names

* adding stop block

* fixing exanmples
This commit is contained in:
Peli de Halleux 2018-01-09 12:46:48 -08:00 committed by GitHub
parent 9890f2340a
commit 892a2d585f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 131 additions and 69 deletions

View File

@ -14,7 +14,7 @@ function accelerate() {
} }
function update() { function update() {
brick.clearScreen() brick.clearScreen()
brick.printLine("speed: " + speed, 1) brick.showString("speed: " + speed, 1)
motors.largeBC.setSpeed(speed) motors.largeBC.setSpeed(speed)
} }
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () { sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {

View File

@ -7,5 +7,5 @@ loops.forever(function () {
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors(); motors.largeBC.stop();
``` ```

View File

@ -9,5 +9,5 @@ loops.forever(function () {
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors(); motors.largeBC.stop();
``` ```

View File

@ -4,10 +4,9 @@
let beep = false let beep = false
beep = true beep = true
control.runInBackground(function () { control.runInBackground(function () {
motors.largeB.setSpeed(-20) motors.largeBC.setSpeed(-20)
motors.largeC.setSpeed(-20)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear) sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.stopAllMotors() motors.largeBC.stop()
beep = false beep = false
}) })
control.runInBackground(function () { control.runInBackground(function () {

View File

@ -11,5 +11,8 @@
"sensors.ColorSensor.onLightChanged|param|handler": "the code to run when detected", "sensors.ColorSensor.onLightChanged|param|handler": "the code to run when detected",
"sensors.ColorSensor.pauseForColor": "Waits for the given color to be detected", "sensors.ColorSensor.pauseForColor": "Waits for the given color to be detected",
"sensors.ColorSensor.pauseForColor|param|color": "the color to detect", "sensors.ColorSensor.pauseForColor|param|color": "the color to detect",
"sensors.ColorSensor.pauseForLight": "Waits for the given color to be detected" "sensors.ColorSensor.pauseForLight": "Waits for the given color to be detected",
"sensors.ColorSensor.setThreshold": "Sets a threshold value",
"sensors.ColorSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.ColorSensor.setThreshold|param|value": "the value threshold"
} }

View File

@ -19,11 +19,13 @@
"sensors.ColorSensor.onLightChanged|block": "on %sensor|%mode|%condition", "sensors.ColorSensor.onLightChanged|block": "on %sensor|%mode|%condition",
"sensors.ColorSensor.pauseForColor|block": "pause %sensor|for color %color", "sensors.ColorSensor.pauseForColor|block": "pause %sensor|for color %color",
"sensors.ColorSensor.pauseForLight|block": "pause %sensor|for %mode|%condition", "sensors.ColorSensor.pauseForLight|block": "pause %sensor|for %mode|%condition",
"sensors.ColorSensor.setThreshold|block": "set %condition|to %value",
"sensors.color1|block": "color 1", "sensors.color1|block": "color 1",
"sensors.color2|block": "color 2", "sensors.color2|block": "color 2",
"sensors.color3|block": "color 3", "sensors.color3|block": "color 3",
"sensors.color4|block": "color 4", "sensors.color4|block": "color 4",
"sensors|block": "sensors", "sensors|block": "sensors",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Color Sensor": "Color Sensor" "{id:group}Color Sensor": "Color Sensor",
"{id:group}Threshold": "Threshold"
} }

View File

@ -152,7 +152,7 @@ namespace sensors {
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=99 //% weight=98
//% group="Color Sensor" //% group="Color Sensor"
color(): ColorSensorColor { color(): ColorSensorColor {
this.setMode(ColorSensorMode.Color) this.setMode(ColorSensorMode.Color)
@ -221,6 +221,20 @@ namespace sensors {
reflectedLight() { reflectedLight() {
return this.light(LightIntensityMode.Reflected); return this.light(LightIntensityMode.Reflected);
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=colorSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8 weight=90
setThreshold(condition: LightCondition, value: number) {
if (condition == LightCondition.Dark)
this.thresholdDetector.setLowThreshold(value)
else
this.thresholdDetector.setHighThreshold(value);
}
} }
//% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3 //% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3

View File

@ -71,7 +71,7 @@
"motors.MotorBase.setBrake": "Sets the automatic brake on or off when the motor is off", "motors.MotorBase.setBrake": "Sets the automatic brake on or off when the motor is off",
"motors.MotorBase.setBrake|param|brake": "a value indicating if the motor should break when off", "motors.MotorBase.setBrake|param|brake": "a value indicating if the motor should break when off",
"motors.MotorBase.setReversed": "Reverses the motor polarity", "motors.MotorBase.setReversed": "Reverses the motor polarity",
"motors.MotorBase.setSpeed": "Sets the motor speed for limited time or distance", "motors.MotorBase.setSpeed": "Sets the motor speed for limited time or distance.",
"motors.MotorBase.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50", "motors.MotorBase.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.MotorBase.setSpeed|param|unit": "(optional) unit of the value", "motors.MotorBase.setSpeed|param|unit": "(optional) unit of the value",
"motors.MotorBase.setSpeed|param|value": "(optional) measured distance or rotation", "motors.MotorBase.setSpeed|param|value": "(optional) measured distance or rotation",

View File

@ -58,6 +58,7 @@
"motors.MotorBase.setBrake|block": "set %motor|brake %brake", "motors.MotorBase.setBrake|block": "set %motor|brake %brake",
"motors.MotorBase.setReversed|block": "set %motor|reversed %reversed", "motors.MotorBase.setReversed|block": "set %motor|reversed %reversed",
"motors.MotorBase.setSpeed|block": "set %motor|speed to %speed=motorSpeedPicker|%", "motors.MotorBase.setSpeed|block": "set %motor|speed to %speed=motorSpeedPicker|%",
"motors.MotorBase.stop|block": "%motors|stop",
"motors.SynchedMotorPair.steer|block": "steer %chassis|turn ratio %turnRatio|speed %speed=motorSpeedPicker|%", "motors.SynchedMotorPair.steer|block": "steer %chassis|turn ratio %turnRatio|speed %speed=motorSpeedPicker|%",
"motors.SynchedMotorPair.tank|block": "tank %motors|%speedLeft=motorSpeedPicker|%|%speedRight=motorSpeedPicker|%", "motors.SynchedMotorPair.tank|block": "tank %motors|%speedLeft=motorSpeedPicker|%|%speedRight=motorSpeedPicker|%",
"motors.largeAB|block": "large A+B", "motors.largeAB|block": "large A+B",

View File

@ -187,7 +187,9 @@ namespace motors {
/** /**
* Stops the motor(s). * Stops the motor(s).
*/ */
//% //% weight=6 blockGap=8
//% group="Move"
//% blockId=motorStop block="%motors|stop"
stop() { stop() {
this.init(); this.init();
stop(this._port, this._brake); stop(this._port, this._brake);
@ -203,7 +205,7 @@ namespace motors {
} }
/** /**
* Sets the motor speed for limited time or distance * Sets the motor speed for limited time or distance.
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50 * @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param value (optional) measured distance or rotation * @param value (optional) measured distance or rotation
* @param unit (optional) unit of the value * @param unit (optional) unit of the value

View File

@ -8,7 +8,7 @@ namespace brick {
//% color="#C8509B" weight=95 icon="\uf10f" //% color="#C8509B" weight=95 icon="\uf10f"
//% labelLineWidth=0 //% labelLineWidth=0
//% groups='["Ultrasonic Sensor", "Touch Sensor", "Color Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Gyro Sensor"]' //% groups='["Touch Sensor", "Color Sensor", "Ultrasonic Sensor", "Gyro Sensor", "Infrared Sensor", "Remote Infrared Beacon", "Threshold"]'
//% groupIcons='["\uf101","\uf103","\uf102","","","\uf104"]' //% groupIcons='["\uf101","\uf103","\uf102","","","\uf104"]'
namespace sensors { namespace sensors {
} }

View File

@ -31,7 +31,7 @@ namespace sensors {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=65 blockGap=8 //% weight=64 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
angle(): number { angle(): number {
if (this.calibrating) if (this.calibrating)
@ -70,7 +70,7 @@ namespace sensors {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% sensor.fieldEditor="ports"
//% weight=65 blockGap=8 //% weight=50 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
calibrate(): void { calibrate(): void {
if (this.calibrating) return; // already in calibration mode if (this.calibrating) return; // already in calibration mode

View File

@ -4,6 +4,9 @@
"sensors.InfraredSensor.pauseUntil": "Waits for the event to occur", "sensors.InfraredSensor.pauseUntil": "Waits for the event to occur",
"sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)", "sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)",
"sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.", "sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.",
"sensors.InfraredSensor.setThreshold": "Sets a threshold value",
"sensors.InfraredSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.InfraredSensor.setThreshold|param|value": "the value threshold",
"sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.", "sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.",
"sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down", "sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down",
"sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised", "sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised",

View File

@ -5,6 +5,7 @@
"sensors.InfraredSensor.pauseUntil|block": "pause until %sensor| %event", "sensors.InfraredSensor.pauseUntil|block": "pause until %sensor| %event",
"sensors.InfraredSensor.proximity|block": "%sensor|proximity", "sensors.InfraredSensor.proximity|block": "%sensor|proximity",
"sensors.InfraredSensor.remoteCommand|block": "%sensor|remote command", "sensors.InfraredSensor.remoteCommand|block": "%sensor|remote command",
"sensors.InfraredSensor.setThreshold|block": "set %condition|to %value",
"sensors.RemoteInfraredBeaconButton.isPressed|block": "%button|is pressed", "sensors.RemoteInfraredBeaconButton.isPressed|block": "%button|is pressed",
"sensors.RemoteInfraredBeaconButton.onEvent|block": "on %button|%event", "sensors.RemoteInfraredBeaconButton.onEvent|block": "on %button|%event",
"sensors.RemoteInfraredBeaconButton.wasPressed|block": "%button|was pressed", "sensors.RemoteInfraredBeaconButton.wasPressed|block": "%button|was pressed",
@ -20,5 +21,6 @@
"sensors|block": "sensors", "sensors|block": "sensors",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Infrared Sensor": "Infrared Sensor", "{id:group}Infrared Sensor": "Infrared Sensor",
"{id:group}Remote Infrared Beacon": "Remote Infrared Beacon" "{id:group}Remote Infrared Beacon": "Remote Infrared Beacon",
"{id:group}Threshold": "Threshold"
} }

View File

@ -250,6 +250,21 @@ namespace sensors {
this._setMode(IrSensorMode.Seek) this._setMode(IrSensorMode.Seek)
return this.getNumber(NumberFormat.UInt16LE, this.channel * 2) return this.getNumber(NumberFormat.UInt16LE, this.channel * 2)
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=irSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8
setThreshold(condition: InfraredSensorEvent, value: number) {
if (condition == InfraredSensorEvent.ObjectNear)
this.proximityThreshold.setLowThreshold(value)
else
this.proximityThreshold.setHighThreshold(value);
}
} }
//% fixedInstance whenUsed block="infrared 1" jres=icons.port1 //% fixedInstance whenUsed block="infrared 1" jres=icons.port1

View File

@ -33,34 +33,34 @@
"music.stopAllSounds|block": "stop all sounds", "music.stopAllSounds|block": "stop all sounds",
"music.tempo|block": "tempo (bpm)", "music.tempo|block": "tempo (bpm)",
"music|block": "music", "music|block": "music",
"sounds.animalsCatPurr|block": "Animals cat purr", "sounds.animalsCatPurr|block": "animals cat purr",
"sounds.animalsDogBark1|block": "Animals dog bark 1", "sounds.animalsDogBark1|block": "animals dog bark 1",
"sounds.animalsDogBark2|block": "Animals dog bark 2", "sounds.animalsDogBark2|block": "animals dog bark 2",
"sounds.animalsDogGrowl|block": "Animals dog growl", "sounds.animalsDogGrowl|block": "animals dog growl",
"sounds.animalsDogSniff|block": "Animals dog sniff", "sounds.animalsDogSniff|block": "animals dog sniff",
"sounds.animalsDogWhine|block": "Animals dog whine", "sounds.animalsDogWhine|block": "animals dog whine",
"sounds.animalsElephantCall|block": "Animals elephant call", "sounds.animalsElephantCall|block": "animals elephant call",
"sounds.animalsInsectBuzz1|block": "Animals insect buzz1", "sounds.animalsInsectBuzz1|block": "animals insect buzz1",
"sounds.animalsInsectBuzz2|block": "Animals insect buzz2", "sounds.animalsInsectBuzz2|block": "animals insect buzz2",
"sounds.animalsInsectChirp|block": "Animals insect chirp", "sounds.animalsInsectChirp|block": "animals insect chirp",
"sounds.animalsSnakeHiss|block": "Animals snake hiss", "sounds.animalsSnakeHiss|block": "animals snake hiss",
"sounds.animalsSnakeRattle|block": "Animals snake rattle", "sounds.animalsSnakeRattle|block": "animals snake rattle",
"sounds.animalsTRexRoar|block": "Animals trex roar", "sounds.animalsTRexRoar|block": "animals trex roar",
"sounds.colorsBlack|block": "Colors black", "sounds.colorsBlack|block": "colors black",
"sounds.colorsBlue|block": "Colors blue", "sounds.colorsBlue|block": "colors blue",
"sounds.colorsBrown|block": "Colors brown", "sounds.colorsBrown|block": "colors brown",
"sounds.colorsGreen|block": "Colors green", "sounds.colorsGreen|block": "colors green",
"sounds.colorsRed|block": "Colors red", "sounds.colorsRed|block": "colors red",
"sounds.colorsWhite|block": "Colors white", "sounds.colorsWhite|block": "colors white",
"sounds.colorsYellow|block": "Colors yellow", "sounds.colorsYellow|block": "colors yellow",
"sounds.communicationBravo|block": "Communication bravo", "sounds.communicationBravo|block": "communication bravo",
"sounds.communicationEv3|block": "Communication ev3", "sounds.communicationEv3|block": "communication ev3",
"sounds.communicationFantastic|block": "Communication fantastic", "sounds.communicationFantastic|block": "communication fantastic",
"sounds.communicationGameOver|block": "Communication game over", "sounds.communicationGameOver|block": "communication game over",
"sounds.communicationGoodJob|block": "communicationGoodJob", "sounds.communicationGoodJob|block": "communicationGoodJob",
"sounds.communicationGoodbye|block": "communication goodbye", "sounds.communicationGoodbye|block": "communication goodbye",
"sounds.communicationGood|block": "communication good", "sounds.communicationGood|block": "communication good",
"sounds.communicationGo|block": "Communication go", "sounds.communicationGo|block": "communication go",
"sounds.communicationHello|block": "communication hello", "sounds.communicationHello|block": "communication hello",
"sounds.communicationHi|block": "communication hi", "sounds.communicationHi|block": "communication hi",
"sounds.communicationLego|block": "communication lego", "sounds.communicationLego|block": "communication lego",
@ -159,7 +159,7 @@
"sounds.systemOverpower|block": "system overpower", "sounds.systemOverpower|block": "system overpower",
"sounds.systemPowerDown|block": "system power down", "sounds.systemPowerDown|block": "system power down",
"sounds.systemReady|block": "system ready", "sounds.systemReady|block": "system ready",
"sounds.systemStartUp|block": "S", "sounds.systemStartUp|block": "system start up",
"{id:category}Music": "Music", "{id:category}Music": "Music",
"{id:category}Sound": "Sound", "{id:category}Sound": "Sound",
"{id:category}Sounds": "Sounds" "{id:category}Sounds": "Sounds"

View File

@ -1,53 +1,53 @@
namespace sounds { namespace sounds {
//% fixedInstance jres block="Animals cat purr" //% fixedInstance jres block="animals cat purr"
export const animalsCatPurr = music.fromWAV(hex``); export const animalsCatPurr = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog bark 1" //% fixedInstance jres block="animals dog bark 1"
export const animalsDogBark1 = music.fromWAV(hex``); export const animalsDogBark1 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog bark 2" //% fixedInstance jres block="animals dog bark 2"
export const animalsDogBark2 = music.fromWAV(hex``); export const animalsDogBark2 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog growl" //% fixedInstance jres block="animals dog growl"
export const animalsDogGrowl = music.fromWAV(hex``); export const animalsDogGrowl = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog sniff" //% fixedInstance jres block="animals dog sniff"
export const animalsDogSniff = music.fromWAV(hex``); export const animalsDogSniff = music.fromWAV(hex``);
//% fixedInstance jres block="Animals dog whine" //% fixedInstance jres block="animals dog whine"
export const animalsDogWhine = music.fromWAV(hex``); export const animalsDogWhine = music.fromWAV(hex``);
//% fixedInstance jres block="Animals elephant call" //% fixedInstance jres block="animals elephant call"
export const animalsElephantCall = music.fromWAV(hex``); export const animalsElephantCall = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect buzz1" //% fixedInstance jres block="animals insect buzz1"
export const animalsInsectBuzz1 = music.fromWAV(hex``); export const animalsInsectBuzz1 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect buzz2" //% fixedInstance jres block="animals insect buzz2"
export const animalsInsectBuzz2 = music.fromWAV(hex``); export const animalsInsectBuzz2 = music.fromWAV(hex``);
//% fixedInstance jres block="Animals insect chirp" //% fixedInstance jres block="animals insect chirp"
export const animalsInsectChirp = music.fromWAV(hex``); export const animalsInsectChirp = music.fromWAV(hex``);
//% fixedInstance jres block="Animals snake hiss" //% fixedInstance jres block="animals snake hiss"
export const animalsSnakeHiss = music.fromWAV(hex``); export const animalsSnakeHiss = music.fromWAV(hex``);
//% fixedInstance jres block="Animals snake rattle" //% fixedInstance jres block="animals snake rattle"
export const animalsSnakeRattle = music.fromWAV(hex``); export const animalsSnakeRattle = music.fromWAV(hex``);
//% fixedInstance jres block="Animals trex roar" //% fixedInstance jres block="animals trex roar"
export const animalsTRexRoar = music.fromWAV(hex``); export const animalsTRexRoar = music.fromWAV(hex``);
//% fixedInstance jres block="Colors black" //% fixedInstance jres block="colors black"
export const colorsBlack = music.fromWAV(hex``); export const colorsBlack = music.fromWAV(hex``);
//% fixedInstance jres block="Colors blue" //% fixedInstance jres block="colors blue"
export const colorsBlue = music.fromWAV(hex``); export const colorsBlue = music.fromWAV(hex``);
//% fixedInstance jres block="Colors brown" //% fixedInstance jres block="colors brown"
export const colorsBrown = music.fromWAV(hex``); export const colorsBrown = music.fromWAV(hex``);
//% fixedInstance jres block="Colors green" //% fixedInstance jres block="colors green"
export const colorsGreen = music.fromWAV(hex``); export const colorsGreen = music.fromWAV(hex``);
//% fixedInstance jres block="Colors red" //% fixedInstance jres block="colors red"
export const colorsRed = music.fromWAV(hex``); export const colorsRed = music.fromWAV(hex``);
//% fixedInstance jres block="Colors white" //% fixedInstance jres block="colors white"
export const colorsWhite = music.fromWAV(hex``); export const colorsWhite = music.fromWAV(hex``);
//% fixedInstance jres block="Colors yellow" //% fixedInstance jres block="colors yellow"
export const colorsYellow = music.fromWAV(hex``); export const colorsYellow = music.fromWAV(hex``);
//% fixedInstance jres block="Communication bravo" //% fixedInstance jres block="communication bravo"
export const communicationBravo = music.fromWAV(hex``); export const communicationBravo = music.fromWAV(hex``);
//% fixedInstance jres block="Communication ev3" //% fixedInstance jres block="communication ev3"
export const communicationEv3 = music.fromWAV(hex``); export const communicationEv3 = music.fromWAV(hex``);
//% fixedInstance jres block="Communication fantastic" //% fixedInstance jres block="communication fantastic"
export const communicationFantastic = music.fromWAV(hex``); export const communicationFantastic = music.fromWAV(hex``);
//% fixedInstance jres block="Communication game over" //% fixedInstance jres block="communication game over"
export const communicationGameOver = music.fromWAV(hex``); export const communicationGameOver = music.fromWAV(hex``);
//% fixedInstance jres block="Communication go" //% fixedInstance jres block="communication go"
export const communicationGo = music.fromWAV(hex``); export const communicationGo = music.fromWAV(hex``);
//% fixedInstance jres block="communicationGoodJob" //% fixedInstance jres block="communicationGoodJob"
export const communicationGoodJob = music.fromWAV(hex``); export const communicationGoodJob = music.fromWAV(hex``);
@ -251,7 +251,7 @@ namespace sounds {
export const systemPowerDown = music.fromWAV(hex``); export const systemPowerDown = music.fromWAV(hex``);
//% fixedInstance jres block="system ready" //% fixedInstance jres block="system ready"
export const systemReady = music.fromWAV(hex``); export const systemReady = music.fromWAV(hex``);
//% fixedInstance jres block=S //% fixedInstance jres block="system start up"
export const systemStartUp = music.fromWAV(hex``); export const systemStartUp = music.fromWAV(hex``);
} }

View File

@ -2,5 +2,8 @@
"sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in centimeters", "sensors.UltraSonicSensor.distance": "Gets the distance from the sonar in centimeters",
"sensors.UltraSonicSensor.onEvent": "Registers code to run when the given color is close", "sensors.UltraSonicSensor.onEvent": "Registers code to run when the given color is close",
"sensors.UltraSonicSensor.onEvent|param|handler": "the code to run when detected", "sensors.UltraSonicSensor.onEvent|param|handler": "the code to run when detected",
"sensors.UltraSonicSensor.pauseUntil": "Waits for the event to occur" "sensors.UltraSonicSensor.pauseUntil": "Waits for the event to occur",
"sensors.UltraSonicSensor.setThreshold": "Sets a threshold value",
"sensors.UltraSonicSensor.setThreshold|param|condition": "the dark or bright light condition",
"sensors.UltraSonicSensor.setThreshold|param|value": "the value threshold"
} }

View File

@ -5,10 +5,12 @@
"sensors.UltraSonicSensor.distance|block": "%sensor|distance", "sensors.UltraSonicSensor.distance|block": "%sensor|distance",
"sensors.UltraSonicSensor.onEvent|block": "on %sensor|%event", "sensors.UltraSonicSensor.onEvent|block": "on %sensor|%event",
"sensors.UltraSonicSensor.pauseUntil|block": "pause until %sensor| %event", "sensors.UltraSonicSensor.pauseUntil|block": "pause until %sensor| %event",
"sensors.UltraSonicSensor.setThreshold|block": "set %condition|to %value",
"sensors.ultrasonic1|block": "ultrasonic 1", "sensors.ultrasonic1|block": "ultrasonic 1",
"sensors.ultrasonic2|block": "ultrasonic 2", "sensors.ultrasonic2|block": "ultrasonic 2",
"sensors.ultrasonic3|block": "ultrasonic 3", "sensors.ultrasonic3|block": "ultrasonic 3",
"sensors.ultrasonic4|block": "ultrasonic 4", "sensors.ultrasonic4|block": "ultrasonic 4",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Threshold": "Threshold",
"{id:group}Ultrasonic Sensor": "Ultrasonic Sensor" "{id:group}Ultrasonic Sensor": "Ultrasonic Sensor"
} }

View File

@ -85,6 +85,22 @@ namespace sensors {
this._setMode(0) this._setMode(0)
return this._query(); return this._query();
} }
/**
* Sets a threshold value
* @param condition the dark or bright light condition
* @param value the value threshold
*/
//% blockId=ultrasonicSetThreshold block="set %condition|to %value"
//% group="Threshold" blockGap=8
setThreshold(condition: UltrasonicSensorEvent, value: number) {
switch(condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
case UltrasonicSensorEvent.ObjectFar: this.promixityThreshold.setHighThreshold(value); break;
case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold = value; break;
}
}
} }
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4 //% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4