Skip to content

Commit

Permalink
added block to power servo with 5v motor pin, as seen in the energy kit
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-inksmith committed Oct 3, 2022
1 parent 8c9d29e commit 2daff98
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions servo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ namespace servos {
P12
}

export enum MotorPin{
//% block="left"
Left,
//% block="right"
Right
}

export enum Power {
//% block="off"
Off = 0,
//% block="on"
On = 1,
}

/**
* Enable a motor pin for access to 5v instead of the 3.3v on the rest of the breakout board
*/
//% block
//% blockId=servo_set block="turn %side motor + pin %state"
//% weight=100
export function motorPinPower (side: MotorPin, state: Power): void {
let pin : DigitalPin;
// Pick a pin
switch (side) {
case MotorPin.Left: pin = cakEnergy.M1_POS; break;
case MotorPin.Right: pin = cakEnergy.M2_POS; break;
default: pin = null; break;
}
if (pin) {
pins.digitalWritePin(pin, state);
}
}

/**
* Function used to return actual AnalogPin from enum
*/
Expand Down

0 comments on commit 2daff98

Please sign in to comment.