118 Commits

Author SHA1 Message Date
MiroChao
f55133bc27 Merge pull request #22 from IsQianGe/patch-2
Correct description
2020-12-19 12:27:32 +08:00
IsQianGe
717b846846 Correct description 2020-12-17 17:33:09 +08:00
Baozhu Zuo
96df6b18b2 update to v0.4.0 2020-12-17 15:26:56 +08:00
Baozhu Zuo
c64162453a Merge pull request #20 from IsQianGe/patch-1
Added V2 version of ultrasonic sensor module
2020-12-15 08:18:04 +08:00
IsQianGe
fa4ff3da22 Added V2 version of ultrasonic sensor module 2020-12-14 20:03:00 +08:00
jerryyip
854654aae4 bump to 0.3.0; support Grove UART WiFi V2 2020-10-12 20:55:42 +08:00
Baozhu Zuo
c0519e7b8b Merge pull request #17 from MKleinSB/master
added blockSetVariable=4digit
2020-09-23 09:36:26 +08:00
Michael Klein
5bfe34365e 0.2.7 2020-09-22 21:36:36 +02:00
Michael Klein
6eab53eb0a fixed gesture sensor 2020-09-22 21:36:20 +02:00
Michael Klein
05160dbb5b 0.2.6 2020-09-22 16:08:26 +02:00
Michael Klein
aa967ae9ed added blockSetVariable=4digit 2020-09-22 16:08:13 +02:00
Michael Klein
7999b286ed 0.2.5 2020-09-17 22:23:07 +02:00
Michael Klein
0a131a114e Aktualisiere test.ts 2020-09-17 22:22:56 +02:00
Michael Klein
859b5cd634 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 22:18:34 +02:00
Michael Klein
f99eb6f2ad 0.2.4 2020-09-17 22:15:08 +02:00
Michael Klein
65171081a9 added block to convert gesture in number 2020-09-17 22:14:57 +02:00
Michael Klein
8d81b2a132 Merge branch 'master' into master 2020-09-17 21:42:16 +02:00
Michael Klein
83157ee090 0.2.3 2020-09-17 21:11:35 +02:00
Michael Klein
b33add3283 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 21:11:26 +02:00
Michael Klein
3dec943bf8 0.2.2 2020-09-17 20:52:54 +02:00
Michael Klein
fe14bba78e Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 20:52:45 +02:00
Michael Klein
d825151823 0.2.1 2020-09-17 20:48:06 +02:00
Michael Klein
f8733cb673 Aktualisiere main.ts 2020-09-17 20:47:07 +02:00
Michael Klein
2a183e0148 0.2.0 2020-09-17 19:19:46 +02:00
Michael Klein
d7d1a45d4f Aktualisiere main.ts 2020-09-17 19:19:34 +02:00
Michael Klein
b1aa39aa1e 0.1.30 2020-09-17 19:17:24 +02:00
Michael Klein
164cfdbab8 Update pxt.json 2020-09-17 19:16:45 +02:00
Michael Klein
09fba508bd Aktualisiere main.ts 2020-09-17 19:16:08 +02:00
Michael Klein
ad17fcc331 0.1.30 2020-09-17 19:14:14 +02:00
Michael Klein
cca1fca078 '17.9.2020, 19:06:02 0.1.29 ' wiederherstellen ' 2020-09-17 19:13:02 +02:00
Michael Klein
4ed40664f7 0.1.30 2020-09-17 19:10:35 +02:00
Michael Klein
f6c7cd50f7 Aktualisiere _locales/de/Grove-strings.json 2020-09-17 19:10:24 +02:00
Michael Klein
492b336347 Aktualisiere main.ts 2020-09-17 19:09:39 +02:00
Michael Klein
21d7264b10 0.1.29 2020-09-17 19:06:02 +02:00
Michael Klein
298797f20b Aktualisiere _locales/de/Grove-strings.json 2020-09-17 19:05:53 +02:00
Michael Klein
a87fd2714e 0.1.28 2020-09-17 19:03:24 +02:00
Michael Klein
d0ead22b5b Aktualisiere main.ts 2020-09-17 19:03:09 +02:00
Michael Klein
16920d2c0b 0.1.27 2020-09-17 18:55:29 +02:00
Michael Klein
232c2d8384 Aktualisiere main.ts 2020-09-17 18:55:21 +02:00
Michael Klein
97b69e754f 0.1.26 2020-09-17 18:50:47 +02:00
Michael Klein
fa8baaec5b Aktualisiere main.ts 2020-09-17 18:50:27 +02:00
Michael Klein
d3f62a3cd0 0.1.25 2020-09-17 18:44:45 +02:00
Michael Klein
43f597510a Aktualisiere main.ts 2020-09-17 18:44:38 +02:00
Michael Klein
90a76ba867 0.1.24 2020-09-17 18:39:22 +02:00
Michael Klein
e1f1204d7e Aktualisiere main.ts 2020-09-17 18:39:14 +02:00
Michael Klein
d79cfa798b 0.1.23 2020-09-17 18:34:46 +02:00
Michael Klein
e82e816c15 Aktualisiere _locales/de/Grove-strings.json 2020-09-17 18:34:37 +02:00
Michael Klein
4c682e0fd3 0.1.22 2020-09-17 18:32:16 +02:00
Michael Klein
74bd8f6e49 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 18:31:59 +02:00
Michael Klein
09d5101805 0.1.21 2020-09-17 18:24:02 +02:00
Michael Klein
5644c815cd Aktualisiere main.ts 2020-09-17 18:22:51 +02:00
Michael Klein
858f78a833 0.1.20 2020-09-17 18:10:52 +02:00
Michael Klein
3fc358d1db Aktualisiere _locales/de/Grove-strings.json 2020-09-17 18:10:44 +02:00
Michael Klein
2155344d68 0.1.19 2020-09-17 18:06:15 +02:00
Michael Klein
8aa1d9a487 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 18:06:05 +02:00
Michael Klein
96039f5012 0.1.18 2020-09-17 17:57:02 +02:00
Michael Klein
b6e60f6db0 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 17:51:13 +02:00
Michael Klein
331c17437c 0.1.17 2020-09-17 17:48:20 +02:00
Michael Klein
ab6d0f92e1 Aktualisiere _locales/de/Grove-strings.json 2020-09-17 17:48:10 +02:00
Michael Klein
7054d263a6 Aktualisiere main.ts, _locales/de/Grove-strings.json 2020-09-17 17:46:57 +02:00
Michael Klein
e1cbce0a3b 0.1.16 2020-09-17 17:37:41 +02:00
Michael Klein
f55c6e4854 change strip-->GroveModule 2020-09-17 17:37:28 +02:00
Amerlander
5c63a615bb Merge pull request #2 from Amerlander/master
0.1.8
2020-09-16 22:01:02 +02:00
Amerlander
6423b1c967 0.1.8 2020-09-16 21:58:56 +02:00
Amerlander
61a4fe5b5f Merge pull request #1 from Amerlander/master
Pin selection
2020-09-16 21:57:50 +02:00
Amerlander
5c6b6627e2 Merge pull request #1 from Amerlander/pr-1
pr-1
2020-09-16 21:56:03 +02:00
Amerlander
8cf2d5c7d5 Aktualisiere pxt.json, README.md, main.ts 2020-09-16 21:55:09 +02:00
Juri
566ce18726 revert 2020-09-16 19:27:17 +02:00
Amerlander
2b3f33d153 Update pxt.json 2020-09-16 19:24:25 +02:00
Amerlander
a51bf960c4 Update pxt.json 2020-09-16 19:23:22 +02:00
Amerlander
981b54a246 Change digital Pin selection 2020-09-14 23:02:41 +02:00
Juri
f933fc45ed Merge remote-tracking branch 'Seeed-Studio/master' 2020-09-11 16:02:15 +02:00
MiroChao
81b6a600cb Update main.ts 2020-01-02 11:20:53 +08:00
MiroChao
f2f5a34bd5 Update main.ts 2020-01-02 11:20:53 +08:00
MiroChao
cfeeada678 Update main.ts 2020-01-02 10:24:24 +08:00
sidikalamini
1d51956960 Update main.ts
update error of x instead of y
2019-12-10 11:26:53 +08:00
Michael Klein
f006a8b115 added german locale 2019-12-10 11:26:30 +08:00
Michael Klein
a97427ee49 fixed missing arguments for blocks 2019-12-10 11:25:44 +08:00
Michael Klein
90d23f74fd add german locale 2019-12-10 11:25:27 +08:00
Michael Klein
dab64d607a 0.1.15 2019-11-13 15:24:26 +01:00
Michael Klein
00fd6808ca Aktualisierungen. 2019-11-13 15:24:19 +01:00
Michael Klein
b61693056a 0.1.14 2019-11-13 15:23:42 +01:00
Michael Klein
a23405acef Aktualisierungen. 2019-11-13 15:23:39 +01:00
Michael Klein
1d6a6a7f2c 0.1.13 2019-11-13 15:19:40 +01:00
Michael Klein
6c0783c5b5 Aktualisierungen. 2019-11-13 15:19:37 +01:00
Michael Klein
727ec603ad 0.1.12 2019-11-13 15:15:18 +01:00
Michael Klein
072d6d6bac Aktualisierungen. 2019-11-13 15:15:14 +01:00
Michael Klein
56a3499405 0.1.11 2019-11-13 15:13:16 +01:00
Michael Klein
3a698164e6 Aktualisierungen. 2019-11-13 15:13:14 +01:00
Michael Klein
1909e7c37f 0.1.10 2019-11-13 14:59:47 +01:00
Michael Klein
6916ca2de0 Aktualisierungen. 2019-11-13 14:59:44 +01:00
Michael Klein
8c0757e0a6 0.1.9 2019-11-13 14:20:45 +01:00
Michael Klein
6752c00178 Aktualisierungen. 2019-11-13 14:20:43 +01:00
Michael Klein
ff03229d6f 0.1.8 2019-11-13 14:16:49 +01:00
Michael Klein
f9e451aaf1 Aktualisierungen. 2019-11-13 14:16:45 +01:00
Michael Klein
ba9a9a0200 0.1.7 2019-11-13 14:14:09 +01:00
Michael Klein
6ef388e50f Aktualisierungen. 2019-11-13 14:14:06 +01:00
adambla76
dff3c9bf76 math.floor fix 2019-11-11 09:37:19 +08:00
adambla76
f1dba411b0 text 2019-11-11 09:37:19 +08:00
adambla76
f65efbaf40 mała zmiana 2019-11-11 09:37:19 +08:00
adambla76
48ab57de24 Update pxt.json
new ver
2019-11-11 09:37:19 +08:00
adambla76
37bcbb378e Update main.ts 2019-11-11 09:37:19 +08:00
adambla76
eba0e205f5 Create testy.ts 2019-11-11 09:37:19 +08:00
Michael Klein
a7d599b5a4 0.1.6 2019-08-01 00:24:04 +02:00
Michael Klein
55465b3773 Updates. 2019-08-01 00:23:56 +02:00
Michael Klein
8b1b69b46b 0.1.5 2019-08-01 00:10:36 +02:00
Michael Klein
8f6e1b5991 Updates. 2019-08-01 00:10:33 +02:00
Michael Klein
0eb0125d96 Update pxt.json 2019-08-01 00:09:43 +02:00
Michael Klein
a6b75f7fd1 Create Grove-strings.json 2019-08-01 00:07:44 +02:00
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
Baozhu Zuo
3ea33acce9 update pxt version 2019-07-30 16:16:05 +08:00
Baozhu Zuo
a0ad605412 test gesture 2019-07-30 16:10:22 +08:00
Baozhu Zuo
bc272c73bd try to fix type error 2019-07-30 15:03:03 +08:00
jerryyip
fe28f60f66 add Grove - Thumb Joystick 2018-09-14 14:11:57 +08:00
jinyuan.weng
1154cb2fef Modify gesture callback. 2018-08-20 17:45:49 +08:00
6 changed files with 715 additions and 206 deletions

7
.gitignore vendored
View File

@@ -45,3 +45,10 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk
node_modules/
pxt_modules/
built/
.python-version
package-lock.json
projects/

102
README.md
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
@@ -47,10 +120,35 @@ Use ``||point||`` to open or close point dispay.
Use ``||clear||`` to clean display.
### Grove - UART WiFi V2
Connect to a WiFi and send data to ThinkSpeak or IFTTT, specify the UART tx and rx pin.
```blocks
grove.setupWifi(
SerialPin.P15,
SerialPin.P1,
BaudRate.BaudRate115200,
"test-ssid",
"test-passwd"
)
basic.forever(() => {
if (grove.wifiOK()) {
basic.showIcon(IconNames.Yes)
} else {
basic.showIcon(IconNames.No)
}
grove.sendToThinkSpeak("write_api_key", 1, 2, 3, 4, 5, 6, 7, 8)
grove.sendToIFTTT("ifttt_event", "ifttt_key", "hello", 'micro', 'bit')
basic.pause(60000)
})
```
## License
MIT
## Supported targets
* for PXT/microbit
* for PXT/calliopemini

View File

@@ -0,0 +1,42 @@
{
"{id:category}Grove": "Grove",
"{id:group}4-Digit": "4 Ziffern Display",
"{id:group}Ultrasonic": "Ultraschall",
"{id:group}Gesture": "Gestenerkennung",
"{id:group}Thumbjoystick": "Grove Joystick",
"GroveGesture.None|block": "keine",
"GroveGesture.Right|block": "rechts",
"GroveGesture.Left|block": "links",
"GroveGesture.Up|block": "auf",
"GroveGesture.Down|block": "nieder",
"GroveGesture.Forward|block": "vorwärts",
"GroveGesture.Backward|block": "rückwärts",
"GroveGesture.Clockwise|block": "Uhrzeigersinn",
"GroveGesture.Anticlockwise|block": "Gegenuhrzeigersinn",
"GroveGesture.Wave|block": "Welle",
"grove.initGesture|block": "initialisiere Grove Gestenerkennung",
"grove.getGestureModel|block": "lies Geste",
"grove.onGesture|block": "wenn Grovegeste |%gesture|",
"grove.measureInCentimeters|block": "Ultraschallsensor (in cm) an |%pin",
"grove.measureInInches|block": "Ultraschallsensor (in inch) an |%pin",
"grove.createDisplay|block": "4-Ziffern Display an|%clkPin|und|%dataPin",
"grove.PAJ7620.init|block": "%GestureModul|initialisiere den Gestensensor",
"grove.PAJ7620.read|block": "%GestureModul|erkenne Geste",
"grove.TM1637.show|block": "%4Digit|zeige Zahl|%dispData|",
"grove.TM1637.set|block": "%4Digit|setze Helligkeit auf|%level|",
"grove.TM1637.bit|block": "%4Digit|zeige Ziffer|%dispData|an Stelle|%bitAddr|",
"grove.TM1637.point|block": "%4Digit|schalte Kommapunkt|%point|",
"grove.TM1637.clear|block": "%4Digit|lösche 4-Ziffern Display",
"GroveJoystickKey.None|block": "Keine",
"GroveJoystickKey.Right|block": "Rechts",
"GroveJoystickKey.Left|block": "Links",
"GroveJoystickKey.Up|block": "Hoch",
"GroveJoystickKey.Down|block": "Runter",
"GroveJoystickKey.UL|block": "Oben links",
"GroveJoystickKey.UR|block": "Oben rechts",
"GroveJoystickKey.LL|block": "Unten links",
"GroveJoystickKey.LR|block": "Unten rechts",
"GroveJoystickKey.Press|block": "Gedrückt",
"grove.onJoystick|block": "wenn Grove - Joystickrichtung|%key an|%xpin|und|%ypin",
"grove.getJoystick|block": "lies Joystickrichtung an|%xpin|und|%ypin"
}

691
main.ts
View File

@@ -1,4 +1,3 @@
const initRegisterArray: number[] = [
0xEF, 0x00, 0x32, 0x29, 0x33, 0x01, 0x34, 0x00, 0x35, 0x01, 0x36, 0x00, 0x37, 0x07, 0x38, 0x17,
0x39, 0x06, 0x3A, 0x12, 0x3F, 0x00, 0x40, 0x02, 0x41, 0xFF, 0x42, 0x01, 0x46, 0x2D, 0x47, 0x0F,
@@ -61,112 +60,36 @@ enum GroveGesture {
Wave = 9
}
enum GroveJoystickKey {
//% block="None"
None = 0,
//% block="Right"
Right = 1,
//% block="Left"
Left = 2,
//% block="Up"
Up = 3,
//% block="Down"
Down = 4,
//% block="Upper left"
UL = 5,
//% block="Upper right"
UR = 6,
//% block="Lower left"
LL = 7,
//% block="Lower right"
LR = 8,
//% block="press"
Press = 9
}
/**
* Functions to operate Grove module.
*/
//% weight=10 color=#9F79EE icon="\uf108" block="Grove"
//% weight=10 color=#9F79EE icon="\uf1b3" block="Grove"
//% groups='["4-Digit","Ultrasonic","Gesture","Thumbjoystick","UartWiFi"]'
namespace grove {
const gestureEventId = 3100;
let lastGesture = GroveGesture.None;
let paj7620: PAJ7620 = undefined;
let distanceBackup: number = 0;
/**
* 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: Action) {
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);
}
})
}
}
/**
* Create a new driver of Grove - Ultrasonic Sensor to measure distances in cm
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
export function measureInCentimeters(pin: DigitalPin): number
{
let duration = 0;
let RangeInCentimeters = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 50000); // Max duration 50 ms
RangeInCentimeters = duration * 153 / 29 / 2 / 100;
if(RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
else RangeInCentimeters = distanceBackup;
basic.pause(50);
return RangeInCentimeters;
}
/**
* Create a new driver Grove - Ultrasonic Sensor to measure distances in inch
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
export function measureInInches(pin: DigitalPin): number
{
let duration = 0;
let RangeInInches = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 100000); // Max duration 100 ms
RangeInInches = duration * 153 / 74 / 2 / 100;
if(RangeInInches > 0) distanceBackup = RangeInInches;
else RangeInInches = distanceBackup;
basic.pause(50);
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;
}
/**
*
*/
@@ -215,8 +138,6 @@ namespace grove {
/**
* Create a new driver of Grove - Gesture
*/
//% blockId=grove_gesture_init block="%strip|initiate the Grove - Gesture"
//% advanced=true
init() {
this.paj7620Init();
basic.pause(200);
@@ -225,8 +146,7 @@ namespace grove {
/**
* Detect and recognize the gestures from Grove - Gesture
*/
//% blockId=grove_gesture_read block="%strip|get gesture"
//% advanced=true
read(): number {
let data = 0, result = 0;
@@ -335,65 +255,83 @@ namespace grove {
* Show a 4 digits number on display
* @param dispData value of number
*/
//% blockId=grove_tm1637_display_number block="%strip|show number|%dispData"
//% blockId=grove_tm1637_display_number block="%4Digit|show number|%dispData"
//% group="4-Digit"
show(dispData: number)
{
let compare_01:number = dispData % 100;
let compare_001:number = dispData % 1000;
if(dispData < 10)
{
this.bit(dispData, 3);
this.bit(0x7f, 2);
this.bit(0x7f, 1);
this.bit(0x7f, 0);
this.buf[3] = dispData;
this.buf[2] = 0x7f;
this.buf[1] = 0x7f;
this.buf[0] = 0x7f;
this.bit(0x7f, 0);
}
else if(dispData < 100)
{
this.bit(dispData % 10, 3);
this.bit((dispData / 10) % 10, 2);
if(dispData > 90){
this.bit(9, 2);
} else{
this.bit(Math.floor(dispData / 10) % 10, 2);
}
this.bit(0x7f, 1);
this.bit(0x7f, 0);
this.buf[3] = dispData % 10;
this.buf[2] = (dispData / 10) % 10;
this.buf[1] = 0x7f;
this.buf[0] = 0x7f;
}
else if(dispData < 1000)
{
this.bit(dispData % 10, 3);
this.bit((dispData / 10) % 10, 2);
this.bit((dispData / 100) % 10, 1);
if(compare_01 > 90){
this.bit(9, 2);
} else{
this.bit(Math.floor(dispData / 10) % 10, 2);
}
if(compare_001 > 900){
this.bit(9, 1);
} else{
this.bit(Math.floor(dispData / 100) % 10, 1);
}
this.bit(0x7f, 0);
this.buf[3] = dispData % 10;
this.buf[2] = (dispData / 10) % 10;
this.buf[1] = (dispData / 100) % 10;
this.buf[0] = 0x7f;
}
else
else if(dispData < 10000)
{
this.bit(dispData % 10, 3);
this.bit((dispData / 10) % 10, 2);
this.bit((dispData / 100) % 10, 1);
this.bit((dispData / 1000) % 10, 0);
this.buf[3] = dispData % 10;
this.buf[2] = (dispData / 10) % 10;
this.buf[1] = (dispData / 100) % 10;
this.buf[0] = (dispData / 1000) % 10;
if(compare_01 > 90){
this.bit(9, 2);
} else{
this.bit(Math.floor(dispData / 10) % 10, 2);
}
if(compare_001 > 900){
this.bit(9, 1);
} else{
this.bit(Math.floor(dispData / 100) % 10, 1);
}
if(dispData > 9000){
this.bit(9, 0);
} else{
this.bit(Math.floor(dispData / 1000) % 10, 0);
}
}
else
{
this.bit(9, 3);
this.bit(9, 2);
this.bit(9, 1);
this.bit(9, 0);
}
}
/**
* Set the brightness level of display at from 0 to 7
* @param level value of brightness level
* @param level value of brightness light level
*/
//% blockId=grove_tm1637_set_display_level block="%strip|brightness level to|%level"
//% blockId=grove_tm1637_set_display_level block="%4Digit|brightness level to|%level"
//% level.min=0 level.max=7
//% group="4-Digit"
set(level: number)
{
this.brightnessLevel = level;
@@ -409,10 +347,10 @@ namespace grove {
* @param dispData value of number
* @param bitAddr value of bit number
*/
//% blockId=grove_tm1637_display_bit block="%strip|show single number|%dispData|at digit|%bitAddr"
//% blockId=grove_tm1637_display_bit block="%4Digit|show single number|%dispData|at digit|%bitAddr"
//% dispData.min=0 dispData.max=9
//% bitAddr.min=0 bitAddr.max=3
//% advanced=true
//% group="4-Digit"
bit(dispData: number, bitAddr: number)
{
if((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3)))
@@ -439,8 +377,8 @@ namespace grove {
* Turn on or off the colon point on Grove - 4-Digit Display
* @param pointEn value of point switch
*/
//% blockId=grove_tm1637_display_point block="%strip|turn|%point|colon point"
//% advanced=true
//% blockId=grove_tm1637_display_point block="%4Digit|turn|%point|colon point"
//% group="4-Digit"
point(point: boolean)
{
this.pointFlag = point;
@@ -454,8 +392,8 @@ namespace grove {
/**
* Clear the display
*/
//% blockId=grove_tm1637_display_clear block="%strip|clear"
//% advanced=true
//% blockId=grove_tm1637_display_clear block="%4Digit|clear"
//% group="4-Digit"
clear()
{
this.bit(0x7f, 0x00);
@@ -464,4 +402,467 @@ namespace grove {
this.bit(0x7f, 0x03);
}
}
}
export class GroveJoystick
{
/**
* Detect position from Grove - Thumb Joystick
* @param xPin
* @param yPin
*/
joyread(xPin: AnalogPin, yPin: AnalogPin): number {
let xdata = 0, ydata = 0, result = 0;
if (xPin && yPin) {
xdata = pins.analogReadPin(xPin);
ydata = pins.analogReadPin(yPin);
if (xdata > 1000) {
result = GroveJoystickKey.Press;
}
else if (xdata > 600) {
if (ydata > 600) result = GroveJoystickKey.UR;
else if (ydata < 400) result = GroveJoystickKey.LR;
else result = GroveJoystickKey.Right;
}
else if (xdata < 400) {
if (ydata > 600) result = GroveJoystickKey.UL;
else if (ydata < 400) result = GroveJoystickKey.LL;
else result = GroveJoystickKey.Left;
}
else {
if (ydata > 600) result = GroveJoystickKey.Up;
else if (ydata < 400) result = GroveJoystickKey.Down;
else result = GroveJoystickKey.None;
}
}
else {
result = GroveJoystickKey.None;
}
return result;
}
}
const gestureEventId = 3100;
const joystickEventID = 3101;
let lastGesture = GroveGesture.None;
let lastJoystick = GroveJoystickKey.None;
let distanceBackup: number = 0;
let joystick = new GroveJoystick();
let paj7620 = new PAJ7620();
// adapted to Calliope mini V2 Core by M.Klein 17.09.2020
/**
* Create a new driver of Grove - Ultrasonic Sensor to measure distances in cm
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_centimeters_v2 block="(V2)Ultrasonic Sensor (in cm) at|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
//% group="Ultrasonic" pin.defl=DigitalPin.C16
export function measureInCentimetersV2(pin: DigitalPin): number
{
let duration = 0;
let RangeInCentimeters = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 50000); // Max duration 50 ms
RangeInCentimeters = duration * 153 / 44 / 2 / 100 ;
if(RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
else RangeInCentimeters = distanceBackup;
basic.pause(50);
return RangeInCentimeters;
}
/**
* Create a new driver Grove - Ultrasonic Sensor to measure distances in inch
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_inches_v2 block="(V2)Ultrasonic Sensor (in inch) at|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
//% group="Ultrasonic" pin.defl=DigitalPin.C16
export function measureInInchesV2(pin: DigitalPin): number
{
let duration = 0;
let RangeInInches = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 100000); // Max duration 100 ms
RangeInInches = duration * 153 / 113 / 2 / 100;
if(RangeInInches > 0) distanceBackup = RangeInInches;
else RangeInInches = distanceBackup;
basic.pause(50);
return RangeInInches;
}
/**
* Create a new driver of Grove - Ultrasonic Sensor to measure distances in cm
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
//% group="Ultrasonic" pin.defl=DigitalPin.C16
export function measureInCentimeters(pin: DigitalPin): number
{
let duration = 0;
let RangeInCentimeters = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 50000); // Max duration 50 ms
RangeInCentimeters = duration * 153 / 29 / 2 / 100;
if(RangeInCentimeters > 0) distanceBackup = RangeInCentimeters;
else RangeInCentimeters = distanceBackup;
basic.pause(50);
return RangeInCentimeters;
}
/**
* Create a new driver Grove - Ultrasonic Sensor to measure distances in inch
* @param pin signal pin of ultrasonic ranger module
*/
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
//% pin.fieldEditor="gridpicker" pin.fieldOptions.columns=4
//% pin.fieldOptions.tooltips="false" pin.fieldOptions.width="250"
//% group="Ultrasonic" pin.defl=DigitalPin.C16
export function measureInInches(pin: DigitalPin): number
{
let duration = 0;
let RangeInInches = 0;
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
pins.digitalWritePin(pin, 1);
control.waitMicros(20);
pins.digitalWritePin(pin, 0);
duration = pins.pulseIn(pin, PulseValue.High, 100000); // Max duration 100 ms
RangeInInches = duration * 153 / 74 / 2 / 100;
if(RangeInInches > 0) distanceBackup = RangeInInches;
else RangeInInches = distanceBackup;
basic.pause(50);
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"
//% clkPin.fieldEditor="gridpicker" clkPin.fieldOptions.columns=4
//% group="4-Digit"
//% clkPin.fieldOptions.tooltips="false" clkPin.fieldOptions.width="250"
//% dataPin.fieldEditor="gridpicker" dataPin.fieldOptions.columns=4
//% clkPin.defl=DigitalPin.C16 dataPin.defl=DigitalPin.C17
//% dataPin.fieldOptions.tooltips="false" dataPin.fieldOptions.width="250"
//% blockSetVariable=4digit
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
*
*/
//% blockId=grove_initgesture block="init gesture"
//% group="Gesture"
export function initGesture() {
if (!paj7620) {
paj7620.init();
}
}
/**
* get Grove Gesture model
*
*/
//% blockId=grove_getgesture block="get gesture model"
//% group="Gesture"
export function getGestureModel(): number {
return paj7620.read();
}
/**
* get Joystick key
*
*/
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%ypin"
//% group="Thumbjoystick" xpin.defl=AnalogPin.C16 ypin.defl=AnalogPin.C17
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
return joystick.joyread(xpin, ypin);
}
/**
* Converts the gesture name to a number
* Useful for comparisons
*/
//% blockId=ggesture block="%key"
//% group="Gesture"
export function ggesture(g: GroveGesture): number {
return g;
}
/**
* 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"
//% group="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);
}
})
}
/**
* Converts the key name to a number
* Useful for comparisons
*/
//% blockId=joystickkey block="%key"
//% group="Thumbjoystick"
export function joystickkey(key: GroveJoystickKey): number {
return key;
}
/**
* 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 at |%xpin|and|%ypin"
//% group="Thumbjoystick" xpin.defl=AnalogPin.C16 ypin.defl=AnalogPin.C17
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
control.onEvent(joystickEventID, key, handler);
control.inBackground(() => {
while(true) {
const key = joystick.joyread(xpin, ypin);
if (key != lastJoystick) {
lastJoystick = key;
control.raiseEvent(joystickEventID, lastJoystick);
}
basic.pause(50);
}
})
}
let isWifiConnected = false;
/**
* Setup Grove - Uart WiFi V2 to connect to Wi-Fi
*/
//% block="Setup Wifi|TX %txPin|RX %rxPin|Baud rate %baudrate|SSID = %ssid|Password = %passwd"
//% group="UartWiFi"
//% txPin.defl=SerialPin.P15
//% rxPin.defl=SerialPin.P1
//% baudRate.defl=BaudRate.BaudRate115200
export function setupWifi(txPin: SerialPin, rxPin: SerialPin, baudRate: BaudRate, ssid: string, passwd: string) {
let result = 0
isWifiConnected = false
serial.redirect(
txPin,
rxPin,
baudRate
)
sendAtCmd("AT")
result = waitAtResponse("OK", "ERROR", "None", 1000)
sendAtCmd("AT+CWMODE=1")
result = waitAtResponse("OK", "ERROR", "None", 1000)
sendAtCmd(`AT+CWJAP="${ssid}","${passwd}"`)
result = waitAtResponse("WIFI GOT IP", "ERROR", "None", 20000)
if (result == 1) {
isWifiConnected = true
}
}
/**
* Check if Grove - Uart WiFi V2 is connected to Wifi
*/
//% block="Wifi OK?"
//% group="UartWiFi"
export function wifiOK() {
return isWifiConnected
}
/**
* Send data to ThinkSpeak
*/
//% block="Send Data to your ThinkSpeak Channel|Write API Key %apiKey|Field1 %field1|Field2 %field2|Field3 %field3|Field4 %field4|Field5 %field5|Field6 %field6|Field7 %field7|Field8 %field8"
//% group="UartWiFi"
//% apiKey.defl="your Write API Key"
export function sendToThinkSpeak(apiKey: string, field1: number, field2: number, field3: number, field4: number, field5: number, field6: number, field7: number, field8: number) {
let result = 0
let retry = 2
// close the previous TCP connection
if (isWifiConnected) {
sendAtCmd("AT+CIPCLOSE")
waitAtResponse("OK", "ERROR", "None", 2000)
}
while (isWifiConnected && retry > 0) {
retry = retry - 1;
// establish TCP connection
sendAtCmd("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80")
result = waitAtResponse("OK", "ALREADY CONNECTED", "ERROR", 2000)
if (result == 3) continue
let data = "GET /update?api_key=" + apiKey
if (!isNaN(field1)) data = data + "&field1=" + field1
if (!isNaN(field2)) data = data + "&field2=" + field2
if (!isNaN(field3)) data = data + "&field3=" + field3
if (!isNaN(field4)) data = data + "&field4=" + field4
if (!isNaN(field5)) data = data + "&field5=" + field5
if (!isNaN(field6)) data = data + "&field6=" + field6
if (!isNaN(field7)) data = data + "&field7=" + field7
if (!isNaN(field8)) data = data + "&field8=" + field8
sendAtCmd("AT+CIPSEND=" + (data.length + 2))
result = waitAtResponse(">", "OK", "ERROR", 2000)
if (result == 3) continue
sendAtCmd(data)
result = waitAtResponse("SEND OK", "SEND FAIL", "ERROR", 5000)
// // close the TCP connection
// sendAtCmd("AT+CIPCLOSE")
// waitAtResponse("OK", "ERROR", "None", 2000)
if (result == 1) break
}
}
/**
* Send data to IFTTT
*/
//% block="Send Data to your IFTTT Event|Event %event|Key %key|value1 %value1|value2 %value2|value3 %value3"
//% group="UartWiFi"
//% event.defl="your Event"
//% key.defl="your Key"
//% value1.defl="hello"
//% value2.defl="micro"
//% value3.defl="bit"
export function sendToIFTTT(event: string, key: string, value1: string, value2: string, value3: string) {
let result = 0
let retry = 2
// close the previous TCP connection
if (isWifiConnected) {
sendAtCmd("AT+CIPCLOSE")
waitAtResponse("OK", "ERROR", "None", 2000)
}
while (isWifiConnected && retry > 0) {
retry = retry - 1;
// establish TCP connection
sendAtCmd("AT+CIPSTART=\"TCP\",\"maker.ifttt.com\",80")
result = waitAtResponse("OK", "ALREADY CONNECTED", "ERROR", 2000)
if (result == 3) continue
let data = "GET /trigger/" + event + "/with/key/" + key
data = data + "?value1=" + value1
data = data + "&value2=" + value2
data = data + "&value3=" + value3
data = data + " HTTP/1.1"
data = data + "\u000D\u000A"
data = data + "User-Agent: curl/7.58.0"
data = data + "\u000D\u000A"
data = data + "Host: maker.ifttt.com"
data = data + "\u000D\u000A"
data = data + "Accept: */*"
data = data + "\u000D\u000A"
sendAtCmd("AT+CIPSEND=" + (data.length + 2))
result = waitAtResponse(">", "OK", "ERROR", 2000)
if (result == 3) continue
sendAtCmd(data)
result = waitAtResponse("SEND OK", "SEND FAIL", "ERROR", 5000)
// // close the TCP connection
// sendAtCmd("AT+CIPCLOSE")
// waitAtResponse("OK", "ERROR", "None", 2000)
if (result == 1) break
}
}
function waitAtResponse(target1: string, target2: string, target3: string, timeout: number) {
let buffer = ""
let start = input.runningTime()
while ((input.runningTime() - start) < timeout) {
buffer += serial.readString()
if (buffer.includes(target1)) return 1
if (buffer.includes(target2)) return 2
if (buffer.includes(target3)) return 3
basic.pause(100)
}
return 0
}
function sendAtCmd(cmd: string) {
serial.writeString(cmd + "\u000D\u000A")
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "Grove",
"version": "0.1.0",
"version": "0.4.0",
"description": "A Microsoft MakeCode package for Seeed Studio Grove module",
"license": "MIT",
"dependencies": {
@@ -9,10 +9,15 @@
"files": [
"README.md",
"main.ts",
"_locales/ja/Grove-strings.json"
"_locales/ja/Grove-strings.json",
"_locales/de/Grove-strings.json"
],
"testFiles": [
"test.ts"
],
"public": true
}
"public": true,
"supportedTargets": [
"calliopemini"
],
"preferredEditor": "tsprj"
}

66
test.ts
View File

@@ -1,56 +1,12 @@
grove.onGesture(GroveGesture.Up, () => {
basic.showString("U")
})
grove.onGesture(GroveGesture.Down, () => {
basic.showString("D")
})
grove.onGesture(GroveGesture.Right, () => {
basic.showString("R")
})
grove.onGesture(GroveGesture.Left, () => {
basic.showString("L")
})
grove.onGesture(GroveGesture.Wave, () => {
basic.showString("W")
})
grove.onGesture(GroveGesture.Clockwise, () => {
basic.showString("C")
})
grove.onGesture(GroveGesture.Anticlockwise, () => {
basic.showString("A")
})
let _4Digit = grove.createDisplay(DigitalPin.C16, DigitalPin.C17)
grove.setupWifi(
SerialPin.P15,
SerialPin.P1,
BaudRate.BaudRate115200,
"test-ssid",
"test-passwd"
)
{
let display = grove.createDisplay(DigitalPin.P0, DigitalPin.P1);
let data = 0;
display.point(true);
display.clear();
display.bit(3, 3);
basic.pause(500);
display.point(false);
display.clear();
display.bit(2, 2);
basic.pause(500);
display.point(true);
display.clear();
display.bit(1, 1);
basic.pause(500);
display.point(false);
display.clear();
display.bit(0, 0);
basic.pause(500);
display.set(7);
while(true)
{
display.show(data ++);
let distance = grove.measureInCentimeters(DigitalPin.P0);
basic.showNumber(distance);
basic.pause(500);
}
}
basic.forever(function () {
_4Digit.bit(6, 1)
})