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