Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0463ddb966 |
75
README.md
75
README.md
@@ -6,88 +6,15 @@ A Microsoft MakeCode package for for Seeed Studio Grove module.
|
|||||||
|
|
||||||
### Grove - Gesture
|
### Grove - Gesture
|
||||||
|
|
||||||
get gesture model.
|
Create gesture events.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
|
||||||
|
|
||||||
grove.onGesture(GroveGesture.Up, () => {
|
grove.onGesture(GroveGesture.Up, () => {
|
||||||
basic.showString("Up");
|
basic.showString("Up");
|
||||||
})
|
})
|
||||||
grove.onGesture(GroveGesture.Down, () => {
|
grove.onGesture(GroveGesture.Down, () => {
|
||||||
basic.showString("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
|
### Grove - Ultrasonic Ranger
|
||||||
|
|||||||
68
main.ts
68
main.ts
@@ -490,26 +490,6 @@ namespace grove {
|
|||||||
return RangeInInches;
|
return RangeInInches;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new driver Grove - 4-Digit Display
|
|
||||||
* @param clkPin value of clk pin number
|
|
||||||
* @param dataPin value of data pin number
|
|
||||||
*/
|
|
||||||
//% blockId=grove_tm1637_create block="4-Digit Display at|%clkPin|and|%dataPin"
|
|
||||||
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637
|
|
||||||
{
|
|
||||||
let display = new TM1637();
|
|
||||||
|
|
||||||
display.buf = pins.createBuffer(4);
|
|
||||||
display.clkPin = clkPin;
|
|
||||||
display.dataPin = dataPin;
|
|
||||||
display.brightnessLevel = 0;
|
|
||||||
display.pointFlag = false;
|
|
||||||
display.clear();
|
|
||||||
|
|
||||||
return display;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init Grove Gesture modules
|
* init Grove Gesture modules
|
||||||
*
|
*
|
||||||
@@ -534,53 +514,7 @@ namespace grove {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%xpin"
|
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%xpin"
|
||||||
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
|
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin) : number {
|
||||||
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.5",
|
"version": "0.1.2",
|
||||||
"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": {
|
||||||
|
|||||||
Reference in New Issue
Block a user