adding a few more blocks

This commit is contained in:
Peli de Halleux 2017-10-24 05:30:05 -07:00
parent 8fa6cf41ca
commit fe46461c4c
5 changed files with 71 additions and 28 deletions

View File

@ -4,34 +4,34 @@
*/
const enum LightsPattern {
//% block=Off enumval=0
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
Off = 0,
//% block=Green enumval=1
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
Green = 1,
//% block=Red enumval=2
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
Red = 2,
//% block=Orange enumval=3
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
Orange = 3,
//% block="Flashing Green" enumval=4
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
GreenFlash = 4,
//% block="Flashing Red" enumval=5
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
RedFlash = 5,
//% block="Flashing Orange" enumval=6
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
OrangeFlash = 6,
//% block="Pulsing Green" enumval=7
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
GreenPulse = 7,
//% block="Pulsing Red" enumval=8
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
RedPulse = 8,
//% block="Pulsing Orange" enumval=9
//% blockIdentity=output.getPattern
//% blockIdentity=output.pattern
OrangePulse = 9,
}
@ -241,7 +241,7 @@ namespace output {
*/
//% blockId=setLights block="set status light %pattern=led_pattern"
//% weight=100 group="Lights"
export function setLights(pattern: number): void {
export function setStatusLight(pattern: number): void {
if (currPattern === pattern)
return
currPattern = pattern
@ -258,7 +258,7 @@ namespace output {
//% blockId=led_pattern block="%pattern"
//% shim=TD_ID colorSecondary="#6e9a36"
//% blockHidden=true useEnumVal=1 pattern.fieldOptions.decompileLiterals=1
export function getPattern(pattern: LightsPattern): number {
export function pattern(pattern: LightsPattern): number {
return pattern;
}
}

View File

@ -5,6 +5,7 @@ const enum GyroSensorMode {
}
namespace input {
//% fixedInstances
export class GyroSensor extends internal.UartSensor {
constructor() {
super()
@ -18,12 +19,32 @@ namespace input {
this._setMode(m)
}
getAngle() {
/**
* Get the current angle from the gyroscope.
* @param color the gyroscope to query the request
*/
//% help=input/gyro/angle
//% block="%color|angle"
//% blockId=gyroGetAngle
//% parts="gyroscope"
//% blockNamespace=input
//% weight=65 blockGap=8
angle() {
this.setMode(GyroSensorMode.Angle)
return this.getNumber(NumberFormat.Int16LE, 0)
}
getRate() {
/**
* Get the current rotation rate from the gyroscope.
* @param color the gyroscope to query the request
*/
//% help=input/gyro/rate
//% block="%color|rotation rate"
//% blockId=gyroGetRate
//% parts="gyroscope"
//% blockNamespace=input
//% weight=65 blockGap=8
rate() {
this.setMode(GyroSensorMode.Rate)
return this.getNumber(NumberFormat.Int16LE, 0)
}

View File

@ -40,6 +40,7 @@ namespace input {
}
}
//% fixedInstance
export class IrSensor extends internal.UartSensor {
private channel: IrRemoteChannel
private buttons: Button[];
@ -92,16 +93,37 @@ namespace input {
this._setMode(m)
}
getDistance() {
/**
* Get the distance measured by the infrared sensor.
* @param ir the infrared sensor
*/
//% help=input/infrared/distance
//% block="%infrared|distance"
//% blockId=infraredGetDistance
//% parts="infrared"
//% blockNamespace=input
//% weight=65 blockGap=8
distance() {
this.setMode(IrSensorMode.Proximity)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
getRemoteCommand() {
/**
* Get the remote commandreceived the infrared sensor.
* @param ir the infrared sensor
*/
//% help=input/infrared/remote-command
//% block="%infrared|remote command"
//% blockId=infraredGetRemoteCommand
//% parts="infrared"
//% blockNamespace=input
//% weight=65 blockGap=8
remoteCommand() {
this.setMode(IrSensorMode.RemoteControl)
return this.getNumber(NumberFormat.UInt8LE, this.channel)
}
// TODO
getDirectionAndDistance() {
this.setMode(IrSensorMode.Seek)
return this.getNumber(NumberFormat.UInt16LE, this.channel * 2)

View File

@ -92,10 +92,10 @@ namespace screen {
* @param x the starting position's x coordinate, eg: 0
* @param y the starting position's x coordinate, eg: 0
*/
//% blockId=screen_drawText block="print %text| at x: %x| y: %y"
//% blockId=screen_print block="print %text| at x: %x| y: %y"
//% weight=99 group="Screen" blockNamespace=output inlineInputMode="inline"
//% x.min=0 x.max=178 y.min=0 y.max=128
export function drawText(text: string, x: number, y: number, mode = Draw.Normal) {
export function print(text: string, x: number, y: number, mode = Draw.Normal) {
x |= 0
y |= 0
if (!currFont) currFont = defaultFont()

View File

@ -1,8 +1,8 @@
screen.clear()
screen.drawText("PXT!", 10, 30, Draw.Quad)
screen.print("PXT!", 10, 30, Draw.Quad)
screen.drawRect(40, 40, 20, 10, Draw.Fill)
output.setLights(LightsPattern.Orange)
output.setStatusLight(LightsPattern.Orange)
screen.drawIcon(100, 50, screen.doubleIcon(screen.heart), Draw.Double | Draw.Transparent)
@ -12,37 +12,37 @@ input.buttonEnter.onEvent(ButtonEvent.Click, () => {
input.buttonLeft.onEvent(ButtonEvent.Click, () => {
screen.drawRect(10, 70, 20, 10, Draw.Fill)
output.setLights(LightsPattern.Red)
output.setStatusLight(LightsPattern.Red)
screen.setFont(screen.microbitFont())
})
input.buttonRight.onEvent(ButtonEvent.Click, () => {
screen.drawText("Right!", 10, 60)
screen.print("Right!", 10, 60)
})
input.buttonDown.onEvent(ButtonEvent.Click, () => {
screen.drawText("Down! ", 10, 60)
screen.print("Down! ", 10, 60)
})
input.buttonUp.onEvent(ButtonEvent.Click, () => {
screen.drawText("Up! ", 10, 60)
screen.print("Up! ", 10, 60)
})
let num = 0
input.touchSensor.onEvent(ButtonEvent.Click, () => {
screen.drawText("Click! " + num, 10, 60)
screen.print("Click! " + num, 10, 60)
num++
})
input.remoteTopLeft.onEvent(ButtonEvent.Click, () => {
screen.drawText("TOPLEFT " + num, 10, 60)
screen.print("TOPLEFT " + num, 10, 60)
num++
})
input.remoteTopRight.onEvent(ButtonEvent.Down, () => {
screen.drawText("TOPRIGH " + num, 10, 60)
screen.print("TOPRIGH " + num, 10, 60)
num++
})
@ -54,7 +54,7 @@ loops.forever(() => {
/*
loops.forever(() => {
let v = input.color.getColor()
screen.drawText(10, 60, v + " ")
screen.print(10, 60, v + " ")
loops.pause(200)
})
*/