4 Commits

Author SHA1 Message Date
Baozhu Zuo
43674e0dc5 add onGesture and onGesture 2019-07-31 16:52:21 +08:00
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
3 changed files with 116 additions and 16 deletions

View File

@@ -6,15 +6,88 @@ A Microsoft MakeCode package for for Seeed Studio Grove module.
### Grove - Gesture
Create gesture events.
get gesture model.
```blocks
grove.onGesture(GroveGesture.Up, () => {
basic.showString("Up");
})
grove.onGesture(GroveGesture.Down, () => {
basic.showString("Down");
})
grove.initGesture()
basic.forever(function () {
if (grove.getGestureModel() == 1) {
basic.showLeds(`
. . # . .
. . . # .
# # # # #
. . . # .
. . # . .
`)
}
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

55
main.ts
View File

@@ -509,7 +509,36 @@ namespace grove {
return display;
}
/**
* init Grove Gesture modules
*
*/
//% blockId=grove_initgesture block="init gesture"
export function initGesture() {
if (!paj7620) {
paj7620.init();
}
}
/**
* get Grove Gesture modle
*
*/
//% blockId=grove_getgesture block="get gesture model"
export function getGestureModel(): number {
return paj7620.read();
}
/**
* 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);
}
/**
* Do something when a gesture is detected by Grove - Gesture
* @param gesture type of gesture to detect
@@ -518,19 +547,17 @@ namespace grove {
//% blockId=grove_gesture_create_event block="on Gesture|%gesture"
export function onGesture(gesture: GroveGesture, handler: () => void) {
control.onEvent(gestureEventId, gesture, handler);
if (!paj7620) {
paj7620.init();
control.inBackground(() => {
while(true) {
const gesture = paj7620.read();
if (gesture != lastGesture) {
lastGesture = gesture;
control.raiseEvent(gestureEventId, lastGesture);
}
basic.pause(50);
paj7620.init();
control.inBackground(() => {
while(true) {
const gesture = paj7620.read();
if (gesture != lastGesture) {
lastGesture = gesture;
control.raiseEvent(gestureEventId, lastGesture);
}
})
}
basic.pause(50);
}
})
}
@@ -541,7 +568,7 @@ namespace grove {
* @param ypin
* @param handler code to run
*/
//% blockId=grove_joystick_create_event block="on Key|%key|at|%xpin|and|%ypin|"
//% blockId=grove_joystick_create_event block="on Key|%key"
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
control.onEvent(joystickEventID, key, handler);
control.inBackground(() => {

View File

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