Skip to content

Commit

Permalink
Merge branch 'master' into changes-in-sensors-category
Browse files Browse the repository at this point in the history
  • Loading branch information
THEb0nny authored Nov 3, 2023
2 parents 2016e17 + c1d3a5c commit 518b411
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 270 deletions.
Binary file added docs/static/tutorials/turtle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/tutorials/motors.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
}, {
"name": "Turtle",
"description": "Encode moves and run them on a driving base",
"cardType": "example",
"url":"/tutorials/turtle",
"cardType": "example"
"imageUrl":"/static/tutorials/turtle.png"
}]
```

Expand Down
36 changes: 11 additions & 25 deletions libs/color-sensor/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace sensors {
else maxModeRange = 100; // ReflectedLightIntensity or AmbientLightIntensity
this._setMode(m); // Change mode
pause(MODE_SWITCH_DELAY);
pauseUntil(() => (this.getStatus() == 8 && (this.mode == ColorSensorMode.RgbRaw ? this._queryArr()[0] : this._query()) <= maxModeRange)); // Pause until mode change
pauseUntil(() => (this.getStatus() == 8 && this._query()[0] <= maxModeRange)); // Pause until mode change
} else {
this._setMode(m);
}
Expand All @@ -98,47 +98,33 @@ namespace sensors {
if (this.mode == ColorSensorMode.Color
|| this.mode == ColorSensorMode.AmbientLightIntensity
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
return this.getNumber(NumberFormat.UInt8LE, 0)
return [this.getNumber(NumberFormat.UInt8LE, 0)];
else if (this.mode == ColorSensorMode.RefRaw)
return this.getNumber(NumberFormat.UInt16LE, 0)
return 0
}

_queryArr(): number[] {
if (this.mode == ColorSensorMode.RgbRaw) {
return [this.getNumber(NumberFormat.UInt16LE, 0)];
else if (this.mode == ColorSensorMode.RgbRaw) {
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
}
return [0, 0, 0];
return [0];
}

_info(): string {
_info() {
switch (this.mode) {
case ColorSensorMode.Color:
return ["none",
return [["none",
"black",
"blue",
"green",
"yellow",
"red",
"white",
"brown"][this._query()];
"brown"][this._query()[0]]];
case ColorSensorMode.AmbientLightIntensity:
case ColorSensorMode.ReflectedLightIntensity:
return `${this._query()}%`;
case ColorSensorMode.RgbRaw:
return "array";
default:
return this._query().toString();
}
}

_infoArr(): string[] {
switch (this.mode) {
return [`${this._query()}%`];
case ColorSensorMode.RgbRaw:
const queryArr = this._queryArr().map(number => number.toString());
return queryArr;
return this._query().map(number => number.toString());
default:
return ["0", "0", "0"];
return [this._query()[0].toString()];
}
}

Expand Down
59 changes: 1 addition & 58 deletions libs/core/buttons.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@

/**
* Patterns for lights under the buttons.
*/
const enum StatusLight {
//% block=off enumval=0
Off = 0,
//% block=green enumval=1
Green = 1,
//% block=red enumval=2
Red = 2,
//% block=orange enumval=3
Orange = 3,
//% block="green flash" enumval=4
GreenFlash = 4,
//% block="red flash" enumval=5
RedFlash = 5,
//% block="orange flash" enumval=6
OrangeFlash = 6,
//% block="green pulse" enumval=7
GreenPulse = 7,
//% block="red pulse" enumval=8
RedPulse = 8,
//% block="orange pulse" enumval=9
OrangePulse = 9,
}

/**
* User interaction on buttons
*/
Expand Down Expand Up @@ -246,34 +219,4 @@ namespace control {
}
return r
}
}

namespace brick {
// the brick starts with the red color
let currPattern: StatusLight = StatusLight.Off;

/**
* Gets the current light pattern.
*/
//% weight=99 group="Buttons"
//% help=brick/status-light
export function statusLight() {
return currPattern;
}

/**
* Set lights.
* @param pattern the lights pattern to use. eg: StatusLight.Orange
*/
//% blockId=setLights block="set status light to %pattern"
//% weight=100 group="Buttons"
//% help=brick/set-status-light
export function setStatusLight(pattern: StatusLight): void {
if (currPattern === pattern)
return
currPattern = pattern;
const cmd = output.createBuffer(2)
cmd[0] = pattern + 48
brick.internal.getBtnsMM().write(cmd)
}
}
}
55 changes: 55 additions & 0 deletions libs/core/indicator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Patterns for lights under the buttons.
*/
const enum StatusLight {
//% block=off enumval=0
Off = 0,
//% block=green enumval=1
Green = 1,
//% block=red enumval=2
Red = 2,
//% block=orange enumval=3
Orange = 3,
//% block="green flash" enumval=4
GreenFlash = 4,
//% block="red flash" enumval=5
RedFlash = 5,
//% block="orange flash" enumval=6
OrangeFlash = 6,
//% block="green pulse" enumval=7
GreenPulse = 7,
//% block="red pulse" enumval=8
RedPulse = 8,
//% block="orange pulse" enumval=9
OrangePulse = 9,
}

namespace brick {
// the brick starts with the red color
let currPattern: StatusLight = StatusLight.Off;

/**
* Gets the current light pattern.
*/
//% weight=99 group="Indicator"
//% help=brick/status-light
export function statusLight() {
return currPattern;
}

/**
* Set lights.
* @param pattern the lights pattern to use. eg: StatusLight.Orange
*/
//% blockId=setLights block="set status light to %pattern"
//% weight=100 group="Indicator"
//% help=brick/set-status-light
export function setStatusLight(pattern: StatusLight): void {
if (currPattern === pattern)
return
currPattern = pattern;
const cmd = output.createBuffer(2)
cmd[0] = pattern + 48
brick.internal.getBtnsMM().write(cmd)
}
}
Loading

0 comments on commit 518b411

Please sign in to comment.