add onGesture and onGesture
This commit is contained in:
parent
2ee4f55c1c
commit
43674e0dc5
10
README.md
10
README.md
@ -9,6 +9,16 @@ A Microsoft MakeCode package for for Seeed Studio Grove module.
|
|||||||
get gesture model.
|
get gesture model.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
|
||||||
|
|
||||||
|
grove.onGesture(GroveGesture.Up, () => {
|
||||||
|
basic.showString("Up");
|
||||||
|
})
|
||||||
|
grove.onGesture(GroveGesture.Down, () => {
|
||||||
|
basic.showString("Down");
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
grove.initGesture()
|
grove.initGesture()
|
||||||
basic.forever(function () {
|
basic.forever(function () {
|
||||||
if (grove.getGestureModel() == 1) {
|
if (grove.getGestureModel() == 1) {
|
||||||
|
45
main.ts
45
main.ts
@ -538,4 +538,49 @@ namespace grove {
|
|||||||
return joystick.read(xpin, ypin);
|
return joystick.read(xpin, ypin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do something when a gesture is detected by Grove - Gesture
|
||||||
|
* @param gesture type of gesture to detect
|
||||||
|
* @param handler code to run
|
||||||
|
*/
|
||||||
|
//% blockId=grove_gesture_create_event block="on Gesture|%gesture"
|
||||||
|
export function onGesture(gesture: GroveGesture, handler: () => void) {
|
||||||
|
control.onEvent(gestureEventId, gesture, handler);
|
||||||
|
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
|
||||||
|
* @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"
|
||||||
|
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
|
||||||
|
control.onEvent(joystickEventID, key, handler);
|
||||||
|
control.inBackground(() => {
|
||||||
|
while(true) {
|
||||||
|
const key = joystick.read(xpin, ypin);
|
||||||
|
if (key != lastJoystick) {
|
||||||
|
lastJoystick = key;
|
||||||
|
control.raiseEvent(joystickEventID, lastJoystick);
|
||||||
|
}
|
||||||
|
basic.pause(50);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
2
pxt.json
2
pxt.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Grove",
|
"name": "Grove",
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"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": {
|
||||||
|
Loading…
Reference in New Issue
Block a user