support for multiple simulated servos
This commit is contained in:
parent
633522c800
commit
7117ba771e
@ -14,7 +14,7 @@ namespace pxsim {
|
|||||||
radioState: RadioState;
|
radioState: RadioState;
|
||||||
// TODO: not singletons
|
// TODO: not singletons
|
||||||
neopixelState: NeoPixelState;
|
neopixelState: NeoPixelState;
|
||||||
microServoState: MicroServoState;
|
servosState: MicroServosState;
|
||||||
fileSystem: FileSystemState;
|
fileSystem: FileSystemState;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -62,7 +62,12 @@ namespace pxsim {
|
|||||||
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
this.builtinParts["lightsensor"] = this.lightSensorState = new LightSensorState();
|
||||||
this.builtinParts["compass"] = this.compassState = new CompassState();
|
this.builtinParts["compass"] = this.compassState = new CompassState();
|
||||||
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
this.builtinParts["neopixel"] = this.neopixelState = new NeoPixelState();
|
||||||
this.builtinParts["microservo"] = this.microServoState = new MicroServoState();
|
this.builtinParts["microservo"] = this.servosState = new MicroServosState({
|
||||||
|
"P0": DAL.MICROBIT_ID_IO_P0,
|
||||||
|
"P1": DAL.MICROBIT_ID_IO_P1,
|
||||||
|
"P2": DAL.MICROBIT_ID_IO_P2,
|
||||||
|
"P3": DAL.MICROBIT_ID_IO_P3
|
||||||
|
});
|
||||||
|
|
||||||
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
this.builtinVisuals["buttonpair"] = () => new visuals.ButtonPairView();
|
||||||
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
this.builtinVisuals["ledmatrix"] = () => new visuals.LedMatrixView();
|
||||||
|
@ -72,12 +72,12 @@ namespace pxsim.pins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function servoWritePin(pinId: number, value: number) {
|
export function servoWritePin(pinId: number, value: number) {
|
||||||
|
let pin = getPin(pinId);
|
||||||
|
if (!pin) return;
|
||||||
|
|
||||||
analogSetPeriod(pinId, 20000);
|
analogSetPeriod(pinId, 20000);
|
||||||
// TODO: per pin state
|
const state = board().servosState.servoState(pinId);
|
||||||
if (board().microServoState.angle != value) {
|
state.setAngle(value);
|
||||||
board().microServoState.angle = value;
|
|
||||||
runtime.queueDisplayUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function servoSetPulse(pinId: number, micros: number) {
|
export function servoSetPulse(pinId: number, micros: number) {
|
||||||
|
Loading…
Reference in New Issue
Block a user