basic motor block support

This commit is contained in:
Peli de Halleux 2016-10-11 22:58:53 -07:00
parent 5d8a1b69f6
commit dff4f3adb3
7 changed files with 76 additions and 1 deletions

View File

@ -238,6 +238,8 @@ declare namespace control {
// TODO DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
}
declare namespace led {
}
declare namespace motors {
}

17
libs/core/motors.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "ksbit.h"
/**
* Blocks to control the onboard motors
*/
//% weight=30
namespace motors {
/**
* Controls the power sent to a single motor
* @param power %percent of power sent to the motor. Negative power goes backward. eg: 50
*/
//% blockId=motor_on block="motor on at %percent|%"
//% parts=dcmotor
void motorOn(int power) {
uBit.soundmotor.Motor_On(power);
}
}

View File

@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" width="488" height="836" viewBox="0 0 488 836">
<g transform="translate(0 -216.362)">
<rect width="34.286" height="122.532" x="226.365" y="929.711" fill="#ccc" ry="16.162"/>
<path fill="gray" d="M23.23 359.456A23.233 23.233 0 0 0 0 382.686v511.428a23.233 23.233 0 0 0 23.23 23.23h38.2v24.117a23.233 23.233 0 0 0 23.23 23.234h317.143a23.233 23.233 0 0 0 23.23-23.23v-24.118h38.197a23.233 23.233 0 0 0 23.23-23.23v-511.43a23.233 23.233 0 0 0-23.23-23.23h-440z"/>
<path fill="#333" d="M23.23 357.82C10.4 357.82.002 368.22 0 381.05v511.427c.002 12.83 10.4 23.23 23.23 23.23h38.2v24.118c2.08 25.815 20.27 23.748 33.1 23.75 0 0-11.976-16.96-12.05-40.988-.057-17.923-9.03-12.008-8.176-39.76 2.743-237.84-2.423-390.158.37-522.93z"/>
<path fill="#fd5" d="M23.508 286.934A23.51 18.415 0 0 0 0 305.347v69.375a23.51 18.415 0 0 0 23.508 18.413h440a23.51 18.415 0 0 0 23.508-18.413v-69.375a23.51 18.415 0 0 0-23.508-18.413h-440z"/>
<path fill="#c87137" d="M77.156 216.362c-5.698 0-10.283 4.588-10.283 10.286v94.03c0 5.7 4.585 10.286 10.283 10.286h24.98c5.697 0 10.284-4.587 10.284-10.285v-94.034c0-5.698-4.587-10.286-10.285-10.286h-24.98zm10.18 10.37h4.018c5.095 0 9.197 4.103 9.197 9.2v28.032c0 5.096-4.1 9.197-9.194 9.197h-4.018c-5.096 0-9.2-4.1-9.2-9.194V235.93c0-5.095 4.104-9.197 9.2-9.197zm288.814-10.37c-5.697 0-10.283 4.588-10.283 10.286v94.03c0 5.7 4.586 10.286 10.283 10.286h24.98c5.697 0 10.284-4.587 10.284-10.285v-94.034c0-5.698-4.587-10.286-10.285-10.286h-24.98zm11.045 11.885h4.02c5.095 0 9.197 4.102 9.197 9.197v28.032c0 5.095-4.102 9.2-9.197 9.2h-4.02c-5.095 0-9.197-4.105-9.197-9.2v-28.032c0-5.095 4.102-9.197 9.197-9.197z"/>
<path fill="#fc0" d="M170.587 306.637a17.633 17.633 0 0 0-17.63 17.63v67.587a17.633 17.633 0 0 0 17.63 17.63h34.852v20.57c0 15.162 12.756 27.915 27.913 27.915h24.976c15.157 0 27.916-12.756 27.916-27.917v-20.57h38.612a17.633 17.633 0 0 0 17.63-17.63v-67.587a17.633 17.633 0 0 0-17.63-17.63H170.585z"/>
<rect width="126.356" height="29.385" x="272.569" y="914.707" fill="#b3b3b3" ry="14.693"/>
<rect width="169.991" height="457.913" x="300.928" y="430.348" fill="#b3b3b3" ry="27.415"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -22,6 +22,7 @@
"game.ts",
"led.cpp",
"led.ts",
"motors.cpp",
"music.ts",
"pins.cpp",
"pins.ts",
@ -31,6 +32,7 @@
"pxtparts.json",
"parts/speaker.svg",
"parts/headphone.svg",
"parts/dcmotor.svg",
"_locales/fr/microbit-jsdoc-strings.json"
],
"public": true,

View File

@ -144,5 +144,26 @@
{"part": true, "pinIndices": [0]},
{"pinIndices": [1]}
]
},
"dcmotor": {
"numberOfPins": 2,
"visual": {
"image": "parts/dcmotor.svg",
"width": 488,
"height": 836,
"pinDistance": 65,
"pinLocations": [
{"x": 89, "y": 48},
{"x": 395, "y": 48} ]
},
"pinDefinitions": [
{ "target": "P1", "style": "croc", "orientation": "-Z"},
{ "target": "ground", "style": "croc", "orientation": "-Z"}
],
"instantiation": {"kind": "singleton"},
"assembly": [
{"part": true, "pinIndices": [0]},
{"pinIndices": [1]}
]
}
}

16
libs/core/shims.d.ts vendored
View File

@ -508,6 +508,22 @@ declare namespace led {
//% parts="ledmatrix" shim=led::screenshot
function screenshot(): Image;
}
/**
* Blocks to control the onboard motors
*/
//% weight=30
declare namespace motors {
/**
* Controls the power sent to a single motor
* @param power %percent of power sent to the motor. Negative power goes backward. eg: 50
*/
//% blockId=motor_on block="motor on at %percent|%"
//% parts=dcmotor shim=motors::motorOn
function motorOn(power: number): void;
}
declare namespace pins {
/**

5
sim/state/soundmotor.ts Normal file
View File

@ -0,0 +1,5 @@
namespace pxsim.motors {
export function motorOn(power: number) {
// TODO
}
}