4 Commits

Author SHA1 Message Date
Baozhu Zuo
2ee4f55c1c update readme and pxt version 2019-07-31 15:51:43 +08:00
Baozhu Zuo
719ec4a2cc update to lastest verion 2019-07-31 15:30:28 +08:00
Baozhu Zuo
902648c6a9 remove onGesture and onJoystick event 2019-07-31 15:23:52 +08:00
Baozhu Zuo
3ea33acce9 update pxt version 2019-07-30 16:16:05 +08:00
3 changed files with 90 additions and 45 deletions

View File

@@ -6,16 +6,79 @@ A Microsoft MakeCode package for for Seeed Studio Grove module.
### Grove - Gesture ### Grove - Gesture
Create gesture events. get gesture model.
```blocks ```blocks
grove.onGesture(GroveGesture.Up, () => { grove.initGesture()
basic.showString("Up"); basic.forever(function () {
}) if (grove.getGestureModel() == 1) {
grove.onGesture(GroveGesture.Down, () => { basic.showLeds(`
basic.showString("Down"); . . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
}
if (grove.getGestureModel() == 2) {
basic.showLeds(`
. . # . .
. # . . .
# # # # #
. # . . .
. . # . .
`)
}
if (grove.getGestureModel() == 3) {
basic.showLeds(`
. . # . .
. # # # .
# . # . #
. . # . .
. . # . .
`)
}
if (grove.getGestureModel() == 4) {
basic.showLeds(`
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .
`)
}
basic.pause(100)
}) })
``` ```
all the model
```
/**
* Grove Gestures
*/
enum GroveGesture {
//% block=None
None = 0,
//% block=Right
Right = 1,
//% block=Left
Left = 2,
//% block=Up
Up = 3,
//% block=Down
Down = 4,
//% block=Forward
Forward = 5,
//% block=Backward
Backward = 6,
//% block=Clockwise
Clockwise = 7,
//% block=Anticlockwise
Anticlockwise = 8,
//% block=Wave
Wave = 9
}
```
### Grove - Ultrasonic Ranger ### Grove - Ultrasonic Ranger

50
main.ts
View File

@@ -511,49 +511,31 @@ namespace grove {
} }
/** /**
* Do something when a gesture is detected by Grove - Gesture * init Grove Gesture modules
* @param gesture type of gesture to detect *
* @param handler code to run
*/ */
//% blockId=grove_gesture_create_event block="on Gesture|%gesture" //% blockId=grove_initgesture block="init gesture"
export function onGesture(gesture: GroveGesture, handler: () => void) { export function initGesture() {
control.onEvent(gestureEventId, gesture, handler);
if (!paj7620) { if (!paj7620) {
paj7620.init(); paj7620.init();
control.inBackground(() => {
while(true) {
const gesture = paj7620.read();
if (gesture != lastGesture) {
lastGesture = gesture;
control.raiseEvent(gestureEventId, lastGesture);
}
basic.pause(50);
}
})
} }
} }
/** /**
* Do something when a key is detected by Grove - Thumb Joystick * get Grove Gesture modle
* @param key type of joystick to detect *
* @param xpin
* @param ypin
* @param handler code to run
*/ */
//% blockId=grove_joystick_create_event block="on Key|%key|at|%xpin|and|%ypin|" //% blockId=grove_getgesture block="get gesture model"
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) { export function getGestureModel(): number {
control.onEvent(joystickEventID, key, handler); return paj7620.read();
control.inBackground(() => {
while(true) {
const key = joystick.read(xpin, ypin);
if (key != lastJoystick) {
lastJoystick = key;
control.raiseEvent(joystickEventID, lastJoystick);
} }
basic.pause(50); /**
* get Joystick key
*
*/
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%xpin"
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
return joystick.read(xpin, ypin);
} }
})
} }
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "Grove", "name": "Grove",
"version": "0.1.0", "version": "0.1.4",
"description": "A Microsoft MakeCode package for Seeed Studio Grove module", "description": "A Microsoft MakeCode package for Seeed Studio Grove module",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {