fixing color / gyro

This commit is contained in:
Peli de Halleux 2017-10-24 15:22:07 -07:00
parent 334d5aca9a
commit c85c68ab68
4 changed files with 26 additions and 15 deletions

View File

@ -23,9 +23,9 @@
"input.Button.onEvent": "Do something when a button or sensor is clicked, double clicked, etc...", "input.Button.onEvent": "Do something when a button or sensor is clicked, double clicked, etc...",
"input.Button.onEvent|param|body": "code to run when the event is raised", "input.Button.onEvent|param|body": "code to run when the event is raised",
"input.Button.wasPressed": "See if the button was pressed again since the last time you checked.", "input.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
"input.ColorSensor.getAmbientLight": "Get current ambient light value from the color sensor.", "input.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
"input.ColorSensor.getColor": "Get the current color from the color sensor.", "input.ColorSensor.color": "Get the current color from the color sensor.",
"input.ColorSensor.getReflectedLight": "Get current reflected light value from the color sensor.", "input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
"input.GyroSensor.angle": "Get the current angle from the gyroscope.", "input.GyroSensor.angle": "Get the current angle from the gyroscope.",
"input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.", "input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
"input.IrSensor.distance": "Get the distance measured by the infrared sensor.", "input.IrSensor.distance": "Get the distance measured by the infrared sensor.",

View File

@ -18,9 +18,9 @@
"input.Button.isPressed|block": "%button|is pressed", "input.Button.isPressed|block": "%button|is pressed",
"input.Button.onEvent|block": "on %button|%event", "input.Button.onEvent|block": "on %button|%event",
"input.Button.wasPressed|block": "%button|was pressed", "input.Button.wasPressed|block": "%button|was pressed",
"input.ColorSensor.getAmbientLight|block": "%color| ambient light", "input.ColorSensor.ambientLight|block": "%color| ambient light",
"input.ColorSensor.getColor|block": "%color| color", "input.ColorSensor.color|block": "%color| color",
"input.ColorSensor.getReflectedLight|block": "%color| reflected light", "input.ColorSensor.reflectedLight|block": "%color| reflected light",
"input.GyroSensor.angle|block": "%color|angle", "input.GyroSensor.angle|block": "%color|angle",
"input.GyroSensor.rate|block": "%color|rotation rate", "input.GyroSensor.rate|block": "%color|rotation rate",
"input.IrSensor.distance|block": "%infrared|distance", "input.IrSensor.distance|block": "%infrared|distance",
@ -34,6 +34,10 @@
"input.color2|block": "color sensor 2", "input.color2|block": "color sensor 2",
"input.color3|block": "color sensor 3", "input.color3|block": "color sensor 3",
"input.color4|block": "color sensor 4", "input.color4|block": "color sensor 4",
"input.gyro1|block": "gyroscope 1",
"input.gyro2|block": "gyroscope 2",
"input.gyro3|block": "gyroscope 3",
"input.gyro4|block": "gyroscope 4",
"input.remoteBottomLeft|block": "remote bottom-left", "input.remoteBottomLeft|block": "remote bottom-left",
"input.remoteBottomRight|block": "remote bottom-right", "input.remoteBottomRight|block": "remote bottom-right",
"input.remoteCenter|block": "remote center", "input.remoteCenter|block": "remote center",
@ -61,6 +65,8 @@
"{id:category}Output": "Output", "{id:category}Output": "Output",
"{id:category}Screen": "Screen", "{id:category}Screen": "Screen",
"{id:category}Serial": "Serial", "{id:category}Serial": "Serial",
"{id:group}Color Sensor": "Color Sensor",
"{id:group}Gyroscope": "Gyroscope",
"{id:group}Lights": "Lights", "{id:group}Lights": "Lights",
"{id:group}Motors": "Motors", "{id:group}Motors": "Motors",
"{id:group}Screen": "Screen" "{id:group}Screen": "Screen"

View File

@ -45,7 +45,8 @@ namespace input {
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=input //% blockNamespace=input
//% weight=65 blockGap=8 //% weight=65 blockGap=8
getAmbientLight() { //% group="Color Sensor"
ambientLight() {
this.setMode(ColorSensorMode.Ambient) this.setMode(ColorSensorMode.Ambient)
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
} }
@ -60,7 +61,8 @@ namespace input {
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=input //% blockNamespace=input
//% weight=64 blockGap=8 //% weight=64 blockGap=8
getReflectedLight(): number { //% group="Color Sensor"
reflectedLight(): number {
this.setMode(ColorSensorMode.Reflect) this.setMode(ColorSensorMode.Reflect)
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
} }
@ -75,7 +77,8 @@ namespace input {
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=input //% blockNamespace=input
//% weight=66 blockGap=8 //% weight=66 blockGap=8
getColor(): ColorSensorColor { //% group="Color Sensor"
color(): ColorSensorColor {
this.setMode(ColorSensorMode.Color) this.setMode(ColorSensorMode.Color)
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
} }

View File

@ -5,7 +5,7 @@ const enum GyroSensorMode {
} }
namespace input { namespace input {
//% fixedInstance //% fixedInstances
export class GyroSensor extends internal.UartSensor { export class GyroSensor extends internal.UartSensor {
constructor(port: number) { constructor(port: number) {
super(port) super(port)
@ -29,6 +29,7 @@ namespace input {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=input //% blockNamespace=input
//% weight=65 blockGap=8 //% weight=65 blockGap=8
//% group="Gyroscope"
angle() { angle() {
this.setMode(GyroSensorMode.Angle) this.setMode(GyroSensorMode.Angle)
return this.getNumber(NumberFormat.Int16LE, 0) return this.getNumber(NumberFormat.Int16LE, 0)
@ -44,21 +45,22 @@ namespace input {
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=input //% blockNamespace=input
//% weight=65 blockGap=8 //% weight=65 blockGap=8
//% group="Gyroscope"
rate() { rate() {
this.setMode(GyroSensorMode.Rate) this.setMode(GyroSensorMode.Rate)
return this.getNumber(NumberFormat.Int16LE, 0) return this.getNumber(NumberFormat.Int16LE, 0)
} }
} }
//% whenUsed //% fixedInstance whenUsed block="gyroscope 1"
export const gyro1: GyroSensor = new GyroSensor(1) export const gyro1: GyroSensor = new GyroSensor(1)
//% whenUsed //% fixedInstance whenUsed block="gyroscope 2"
export const gyro2: GyroSensor = new GyroSensor(2) export const gyro2: GyroSensor = new GyroSensor(2)
//% whenUsed //% fixedInstance whenUsed block="gyroscope 3"
export const gyro3: GyroSensor = new GyroSensor(3) export const gyro3: GyroSensor = new GyroSensor(3)
//% whenUsed //% fixedInstance whenUsed block="gyroscope 4"
export const gyro4: GyroSensor = new GyroSensor(4) export const gyro4: GyroSensor = new GyroSensor(4)
} }