Compare commits
114 Commits
Author | SHA1 | Date | |
---|---|---|---|
445e3e2103 | |||
|
e1e2634801 | ||
|
c585249c82 | ||
|
6f841cdabc | ||
|
1548cd4b9c | ||
|
f55133bc27 | ||
|
717b846846 | ||
|
96df6b18b2 | ||
|
c64162453a | ||
|
fa4ff3da22 | ||
|
854654aae4 | ||
|
c0519e7b8b | ||
|
5bfe34365e | ||
|
6eab53eb0a | ||
|
05160dbb5b | ||
|
aa967ae9ed | ||
|
7999b286ed | ||
|
0a131a114e | ||
|
859b5cd634 | ||
|
f99eb6f2ad | ||
|
65171081a9 | ||
|
8d81b2a132 | ||
|
83157ee090 | ||
|
b33add3283 | ||
|
3dec943bf8 | ||
|
fe14bba78e | ||
|
d825151823 | ||
|
f8733cb673 | ||
|
2a183e0148 | ||
|
d7d1a45d4f | ||
|
b1aa39aa1e | ||
|
164cfdbab8 | ||
|
09fba508bd | ||
|
ad17fcc331 | ||
|
cca1fca078 | ||
|
4ed40664f7 | ||
|
f6c7cd50f7 | ||
|
492b336347 | ||
|
21d7264b10 | ||
|
298797f20b | ||
|
a87fd2714e | ||
|
d0ead22b5b | ||
|
16920d2c0b | ||
|
232c2d8384 | ||
|
97b69e754f | ||
|
fa8baaec5b | ||
|
d3f62a3cd0 | ||
|
43f597510a | ||
|
90a76ba867 | ||
|
e1f1204d7e | ||
|
d79cfa798b | ||
|
e82e816c15 | ||
|
4c682e0fd3 | ||
|
74bd8f6e49 | ||
|
09d5101805 | ||
|
5644c815cd | ||
|
858f78a833 | ||
|
3fc358d1db | ||
|
2155344d68 | ||
|
8aa1d9a487 | ||
|
96039f5012 | ||
|
b6e60f6db0 | ||
|
331c17437c | ||
|
ab6d0f92e1 | ||
|
7054d263a6 | ||
|
e1cbce0a3b | ||
|
f55c6e4854 | ||
|
5c63a615bb | ||
|
6423b1c967 | ||
|
61a4fe5b5f | ||
|
5c6b6627e2 | ||
|
8cf2d5c7d5 | ||
|
566ce18726 | ||
|
2b3f33d153 | ||
|
a51bf960c4 | ||
|
981b54a246 | ||
|
f933fc45ed | ||
|
81b6a600cb | ||
|
f2f5a34bd5 | ||
|
cfeeada678 | ||
|
1d51956960 | ||
|
f006a8b115 | ||
|
a97427ee49 | ||
|
90d23f74fd | ||
|
dab64d607a | ||
|
00fd6808ca | ||
|
b61693056a | ||
|
a23405acef | ||
|
1d6a6a7f2c | ||
|
6c0783c5b5 | ||
|
727ec603ad | ||
|
072d6d6bac | ||
|
56a3499405 | ||
|
3a698164e6 | ||
|
1909e7c37f | ||
|
6916ca2de0 | ||
|
8c0757e0a6 | ||
|
6752c00178 | ||
|
ff03229d6f | ||
|
f9e451aaf1 | ||
|
ba9a9a0200 | ||
|
6ef388e50f | ||
|
dff3c9bf76 | ||
|
f1dba411b0 | ||
|
f65efbaf40 | ||
|
48ab57de24 | ||
|
37bcbb378e | ||
|
eba0e205f5 | ||
|
a7d599b5a4 | ||
|
55465b3773 | ||
|
8b1b69b46b | ||
|
8f6e1b5991 | ||
|
0eb0125d96 | ||
|
a6b75f7fd1 |
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 Seeed Studio
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
27
README.md
27
README.md
@ -120,10 +120,35 @@ Use ``||point||`` to open or close point dispay.
|
|||||||
|
|
||||||
Use ``||clear||`` to clean display.
|
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
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
## Supported targets
|
## Supported targets
|
||||||
|
|
||||||
* for PXT/microbit
|
* for PXT/calliopemini
|
||||||
|
42
_locales/de/Grove-strings.json
Normal file
42
_locales/de/Grove-strings.json
Normal 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"
|
||||||
|
}
|
@ -20,5 +20,8 @@
|
|||||||
"grove.TM1637.set|block": "%strip|[Grove - 4桁ディスプレイ]|明るさを|%level|に変更する",
|
"grove.TM1637.set|block": "%strip|[Grove - 4桁ディスプレイ]|明るさを|%level|に変更する",
|
||||||
"grove.TM1637.bit|block": "%strip|[Grove - 4桁ディスプレイ]|%dispData|を|%bitAddr|桁目に表示する",
|
"grove.TM1637.bit|block": "%strip|[Grove - 4桁ディスプレイ]|%dispData|を|%bitAddr|桁目に表示する",
|
||||||
"grove.TM1637.point|block": "%strip|[Grove - 4桁ディスプレイ]|コロンの表示を|%point|に変更する",
|
"grove.TM1637.point|block": "%strip|[Grove - 4桁ディスプレイ]|コロンの表示を|%point|に変更する",
|
||||||
"grove.TM1637.clear|block": "%strip|[Grove - 4桁ディスプレイ]|表示を消す"
|
"grove.TM1637.clear|block": "%strip|[Grove - 4桁ディスプレイ]|表示を消す",
|
||||||
}
|
"grove.aht20ReadTemperatureC|block": "[Grove - 温湿度センサー]|温度(℃)を読み取る",
|
||||||
|
"grove.aht20ReadTemperatureF|block": "[Grove - 温湿度センサー]|温度(℉)を読み取る",
|
||||||
|
"grove.aht20ReadHumidity|block": "[Grove - 温湿度センサー]|湿度を読み取る"
|
||||||
|
}
|
||||||
|
71
blocks/GroveAHT20.ts
Normal file
71
blocks/GroveAHT20.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* Grove - AHT20 Custom Block
|
||||||
|
*/
|
||||||
|
//% groups=['AHT20']
|
||||||
|
namespace grove
|
||||||
|
{
|
||||||
|
function Read(aht20: grove.sensors.AHT20): { Humidity: number, Temperature: number }
|
||||||
|
{
|
||||||
|
if (!aht20.GetState().Calibrated)
|
||||||
|
{
|
||||||
|
aht20.Initialization();
|
||||||
|
if (!aht20.GetState().Calibrated) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
aht20.TriggerMeasurement();
|
||||||
|
for (let i = 0; ; ++i)
|
||||||
|
{
|
||||||
|
if (!aht20.GetState().Busy) break;
|
||||||
|
if (i >= 500) return null;
|
||||||
|
basic.pause(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return aht20.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the temperature(°C) from Grove-AHT20(SKU#101990644)
|
||||||
|
*/
|
||||||
|
//% group="AHT20"
|
||||||
|
//% block="[Grove - Temp&Humi Sensor]|Read the temperature(°C))"
|
||||||
|
//% weight=3
|
||||||
|
export function aht20ReadTemperatureC(): number
|
||||||
|
{
|
||||||
|
const aht20 = new grove.sensors.AHT20();
|
||||||
|
const val = Read(aht20);
|
||||||
|
if (val == null) return null;
|
||||||
|
|
||||||
|
return val.Temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the temperature(°F) from Grove-AHT20(SKU#101990644)
|
||||||
|
*/
|
||||||
|
//% group="AHT20"
|
||||||
|
//% block="[Grove - Temp&Humi Sensor]|Read the temperature(°F))"
|
||||||
|
//% weight=2
|
||||||
|
export function aht20ReadTemperatureF(): number
|
||||||
|
{
|
||||||
|
const aht20 = new grove.sensors.AHT20();
|
||||||
|
const val = Read(aht20);
|
||||||
|
if (val == null) return null;
|
||||||
|
|
||||||
|
return val.Temperature * 9 / 5 + 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the humidity from Grove-AHT20(SKU#101990644)
|
||||||
|
*/
|
||||||
|
//% group="AHT20"
|
||||||
|
//% block="[Grove - Temp&Humi Sensor]|Read the humidity"
|
||||||
|
//% weight=1
|
||||||
|
export function aht20ReadHumidity(): number
|
||||||
|
{
|
||||||
|
const aht20 = new grove.sensors.AHT20();
|
||||||
|
const val = Read(aht20);
|
||||||
|
if (val == null) return null;
|
||||||
|
|
||||||
|
return val.Humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
406
main.ts
406
main.ts
@ -61,25 +61,25 @@ enum GroveGesture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GroveJoystickKey {
|
enum GroveJoystickKey {
|
||||||
//% block=None
|
//% block="None"
|
||||||
None = 0,
|
None = 0,
|
||||||
//% block=Right
|
//% block="Right"
|
||||||
Right = 1,
|
Right = 1,
|
||||||
//% block=Left
|
//% block="Left"
|
||||||
Left = 2,
|
Left = 2,
|
||||||
//% block=Up
|
//% block="Up"
|
||||||
Up = 3,
|
Up = 3,
|
||||||
//% block=Down
|
//% block="Down"
|
||||||
Down = 4,
|
Down = 4,
|
||||||
//% block=Upper left
|
//% block="Upper left"
|
||||||
UL = 5,
|
UL = 5,
|
||||||
//% block=Upper right
|
//% block="Upper right"
|
||||||
UR = 6,
|
UR = 6,
|
||||||
//% block=Lower left
|
//% block="Lower left"
|
||||||
LL = 7,
|
LL = 7,
|
||||||
//% block=Lower right
|
//% block="Lower right"
|
||||||
LR = 8,
|
LR = 8,
|
||||||
//% block=press
|
//% block="press"
|
||||||
Press = 9
|
Press = 9
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,8 @@ enum GroveJoystickKey {
|
|||||||
/**
|
/**
|
||||||
* Functions to operate Grove module.
|
* 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 {
|
namespace grove {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -137,8 +138,6 @@ namespace grove {
|
|||||||
/**
|
/**
|
||||||
* Create a new driver of Grove - Gesture
|
* Create a new driver of Grove - Gesture
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_gesture_init block="%strip|initiate the Grove - Gesture"
|
|
||||||
//% advanced=true
|
|
||||||
init() {
|
init() {
|
||||||
this.paj7620Init();
|
this.paj7620Init();
|
||||||
basic.pause(200);
|
basic.pause(200);
|
||||||
@ -147,8 +146,7 @@ namespace grove {
|
|||||||
/**
|
/**
|
||||||
* Detect and recognize the gestures from Grove - Gesture
|
* Detect and recognize the gestures from Grove - Gesture
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_gesture_read block="%strip|get gesture"
|
|
||||||
//% advanced=true
|
|
||||||
read(): number {
|
read(): number {
|
||||||
let data = 0, result = 0;
|
let data = 0, result = 0;
|
||||||
|
|
||||||
@ -257,65 +255,83 @@ namespace grove {
|
|||||||
* Show a 4 digits number on display
|
* Show a 4 digits number on display
|
||||||
* @param dispData value of number
|
* @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)
|
show(dispData: number)
|
||||||
{
|
{
|
||||||
|
let compare_01:number = dispData % 100;
|
||||||
|
let compare_001:number = dispData % 1000;
|
||||||
|
|
||||||
if(dispData < 10)
|
if(dispData < 10)
|
||||||
{
|
{
|
||||||
this.bit(dispData, 3);
|
this.bit(dispData, 3);
|
||||||
this.bit(0x7f, 2);
|
this.bit(0x7f, 2);
|
||||||
this.bit(0x7f, 1);
|
this.bit(0x7f, 1);
|
||||||
this.bit(0x7f, 0);
|
this.bit(0x7f, 0);
|
||||||
|
|
||||||
this.buf[3] = dispData;
|
|
||||||
this.buf[2] = 0x7f;
|
|
||||||
this.buf[1] = 0x7f;
|
|
||||||
this.buf[0] = 0x7f;
|
|
||||||
}
|
}
|
||||||
else if(dispData < 100)
|
else if(dispData < 100)
|
||||||
{
|
{
|
||||||
this.bit(dispData % 10, 3);
|
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, 1);
|
||||||
this.bit(0x7f, 0);
|
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)
|
else if(dispData < 1000)
|
||||||
{
|
{
|
||||||
this.bit(dispData % 10, 3);
|
this.bit(dispData % 10, 3);
|
||||||
this.bit((dispData / 10) % 10, 2);
|
if(compare_01 > 90){
|
||||||
this.bit((dispData / 100) % 10, 1);
|
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.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, 3);
|
||||||
this.bit((dispData / 10) % 10, 2);
|
if(compare_01 > 90){
|
||||||
this.bit((dispData / 100) % 10, 1);
|
this.bit(9, 2);
|
||||||
this.bit((dispData / 1000) % 10, 0);
|
} else{
|
||||||
|
this.bit(Math.floor(dispData / 10) % 10, 2);
|
||||||
this.buf[3] = dispData % 10;
|
}
|
||||||
this.buf[2] = (dispData / 10) % 10;
|
if(compare_001 > 900){
|
||||||
this.buf[1] = (dispData / 100) % 10;
|
this.bit(9, 1);
|
||||||
this.buf[0] = (dispData / 1000) % 10;
|
} 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
|
* 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
|
//% level.min=0 level.max=7
|
||||||
|
//% group="4-Digit"
|
||||||
set(level: number)
|
set(level: number)
|
||||||
{
|
{
|
||||||
this.brightnessLevel = level;
|
this.brightnessLevel = level;
|
||||||
@ -331,10 +347,10 @@ namespace grove {
|
|||||||
* @param dispData value of number
|
* @param dispData value of number
|
||||||
* @param bitAddr value of bit 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
|
//% dispData.min=0 dispData.max=9
|
||||||
//% bitAddr.min=0 bitAddr.max=3
|
//% bitAddr.min=0 bitAddr.max=3
|
||||||
//% advanced=true
|
//% group="4-Digit"
|
||||||
bit(dispData: number, bitAddr: number)
|
bit(dispData: number, bitAddr: number)
|
||||||
{
|
{
|
||||||
if((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3)))
|
if((dispData == 0x7f) || ((dispData <= 9) && (bitAddr <= 3)))
|
||||||
@ -361,8 +377,8 @@ namespace grove {
|
|||||||
* Turn on or off the colon point on Grove - 4-Digit Display
|
* Turn on or off the colon point on Grove - 4-Digit Display
|
||||||
* @param pointEn value of point switch
|
* @param pointEn value of point switch
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_point block="%strip|turn|%point|colon point"
|
//% blockId=grove_tm1637_display_point block="%4Digit|turn|%point|colon point"
|
||||||
//% advanced=true
|
//% group="4-Digit"
|
||||||
point(point: boolean)
|
point(point: boolean)
|
||||||
{
|
{
|
||||||
this.pointFlag = point;
|
this.pointFlag = point;
|
||||||
@ -376,8 +392,8 @@ namespace grove {
|
|||||||
/**
|
/**
|
||||||
* Clear the display
|
* Clear the display
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_display_clear block="%strip|clear"
|
//% blockId=grove_tm1637_display_clear block="%4Digit|clear"
|
||||||
//% advanced=true
|
//% group="4-Digit"
|
||||||
clear()
|
clear()
|
||||||
{
|
{
|
||||||
this.bit(0x7f, 0x00);
|
this.bit(0x7f, 0x00);
|
||||||
@ -395,9 +411,9 @@ namespace grove {
|
|||||||
* @param xPin
|
* @param xPin
|
||||||
* @param yPin
|
* @param yPin
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_joystick_read block="%strip|read position of joystick"
|
|
||||||
//% advanced=true
|
joyread(xPin: AnalogPin, yPin: AnalogPin): number {
|
||||||
read(xPin: AnalogPin, yPin: AnalogPin): number {
|
|
||||||
let xdata = 0, ydata = 0, result = 0;
|
let xdata = 0, ydata = 0, result = 0;
|
||||||
if (xPin && yPin) {
|
if (xPin && yPin) {
|
||||||
xdata = pins.analogReadPin(xPin);
|
xdata = pins.analogReadPin(xPin);
|
||||||
@ -435,12 +451,78 @@ namespace grove {
|
|||||||
let distanceBackup: number = 0;
|
let distanceBackup: number = 0;
|
||||||
let joystick = new GroveJoystick();
|
let joystick = new GroveJoystick();
|
||||||
let paj7620 = new PAJ7620();
|
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
|
* Create a new driver of Grove - Ultrasonic Sensor to measure distances in cm
|
||||||
* @param pin signal pin of ultrasonic ranger module
|
* @param pin signal pin of ultrasonic ranger module
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_ultrasonic_centimeters block="Ultrasonic Sensor (in cm) at|%pin"
|
//% 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
|
export function measureInCentimeters(pin: DigitalPin): number
|
||||||
{
|
{
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
@ -468,6 +550,9 @@ namespace grove {
|
|||||||
* @param pin signal pin of ultrasonic ranger module
|
* @param pin signal pin of ultrasonic ranger module
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_ultrasonic_inches block="Ultrasonic Sensor (in inch) at|%pin"
|
//% 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
|
export function measureInInches(pin: DigitalPin): number
|
||||||
{
|
{
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
@ -496,6 +581,13 @@ namespace grove {
|
|||||||
* @param dataPin value of data pin number
|
* @param dataPin value of data pin number
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_tm1637_create block="4-Digit Display at|%clkPin|and|%dataPin"
|
//% 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
|
export function createDisplay(clkPin: DigitalPin, dataPin: DigitalPin): TM1637
|
||||||
{
|
{
|
||||||
let display = new TM1637();
|
let display = new TM1637();
|
||||||
@ -515,6 +607,7 @@ namespace grove {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_initgesture block="init gesture"
|
//% blockId=grove_initgesture block="init gesture"
|
||||||
|
//% group="Gesture"
|
||||||
export function initGesture() {
|
export function initGesture() {
|
||||||
if (!paj7620) {
|
if (!paj7620) {
|
||||||
paj7620.init();
|
paj7620.init();
|
||||||
@ -522,10 +615,11 @@ namespace grove {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get Grove Gesture modle
|
* get Grove Gesture model
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_getgesture block="get gesture model"
|
//% blockId=grove_getgesture block="get gesture model"
|
||||||
|
//% group="Gesture"
|
||||||
export function getGestureModel(): number {
|
export function getGestureModel(): number {
|
||||||
return paj7620.read();
|
return paj7620.read();
|
||||||
}
|
}
|
||||||
@ -533,18 +627,29 @@ namespace grove {
|
|||||||
* get Joystick key
|
* get Joystick key
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_getjoystick block="get joystick key at|%xpin|and|%xpin"
|
//% 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 {
|
export function getJoystick(xpin: AnalogPin, ypin: AnalogPin): number {
|
||||||
return joystick.read(xpin, ypin);
|
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
|
* Do something when a gesture is detected by Grove - Gesture
|
||||||
* @param gesture type of gesture to detect
|
* @param gesture type of gesture to detect
|
||||||
* @param handler code to run
|
* @param handler code to run
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_gesture_create_event block="on Gesture|%gesture"
|
//% blockId=grove_gesture_create_event block="on Gesture|%gesture"
|
||||||
|
//% group="Gesture"
|
||||||
export function onGesture(gesture: GroveGesture, handler: () => void) {
|
export function onGesture(gesture: GroveGesture, handler: () => void) {
|
||||||
control.onEvent(gestureEventId, gesture, handler);
|
control.onEvent(gestureEventId, gesture, handler);
|
||||||
paj7620.init();
|
paj7620.init();
|
||||||
@ -560,6 +665,15 @@ namespace grove {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Do something when a key is detected by Grove - Thumb Joystick
|
||||||
@ -568,12 +682,14 @@ namespace grove {
|
|||||||
* @param ypin
|
* @param ypin
|
||||||
* @param handler code to run
|
* @param handler code to run
|
||||||
*/
|
*/
|
||||||
//% blockId=grove_joystick_create_event block="on Key|%key"
|
//% 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) {
|
export function onJoystick(key: GroveJoystickKey, xpin: AnalogPin, ypin: AnalogPin, handler: () => void) {
|
||||||
control.onEvent(joystickEventID, key, handler);
|
control.onEvent(joystickEventID, key, handler);
|
||||||
control.inBackground(() => {
|
control.inBackground(() => {
|
||||||
while(true) {
|
while(true) {
|
||||||
const key = joystick.read(xpin, ypin);
|
const key = joystick.joyread(xpin, ypin);
|
||||||
if (key != lastJoystick) {
|
if (key != lastJoystick) {
|
||||||
lastJoystick = key;
|
lastJoystick = key;
|
||||||
control.raiseEvent(joystickEventID, lastJoystick);
|
control.raiseEvent(joystickEventID, lastJoystick);
|
||||||
@ -583,4 +699,170 @@ namespace grove {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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 ThingSpeak 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\",\"iot.rlp.schule\",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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
13
pxt.json
13
pxt.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Grove",
|
"name": "Grove",
|
||||||
"version": "0.1.5",
|
"version": "0.5.0",
|
||||||
"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": {
|
||||||
@ -9,10 +9,17 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"README.md",
|
"README.md",
|
||||||
"main.ts",
|
"main.ts",
|
||||||
"_locales/ja/Grove-strings.json"
|
"blocks/GroveAHT20.ts",
|
||||||
|
"_locales/ja/Grove-strings.json",
|
||||||
|
"_locales/de/Grove-strings.json",
|
||||||
|
"sensors/AHT20.ts"
|
||||||
],
|
],
|
||||||
"testFiles": [
|
"testFiles": [
|
||||||
"test.ts"
|
"test.ts"
|
||||||
],
|
],
|
||||||
"public": true
|
"public": true,
|
||||||
|
"supportedTargets": [
|
||||||
|
"calliopemini"
|
||||||
|
],
|
||||||
|
"preferredEditor": "tsprj"
|
||||||
}
|
}
|
||||||
|
87
sensors/AHT20.ts
Normal file
87
sensors/AHT20.ts
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
namespace grove
|
||||||
|
{
|
||||||
|
export namespace sensors
|
||||||
|
{
|
||||||
|
|
||||||
|
export class AHT20
|
||||||
|
{
|
||||||
|
public constructor(address: number = 0x38)
|
||||||
|
{
|
||||||
|
this._Address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Initialization(): AHT20
|
||||||
|
{
|
||||||
|
const buf = pins.createBuffer(3);
|
||||||
|
buf[0] = 0xbe;
|
||||||
|
buf[1] = 0x08;
|
||||||
|
buf[2] = 0x00;
|
||||||
|
pins.i2cWriteBuffer(this._Address, buf, false);
|
||||||
|
basic.pause(10);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TriggerMeasurement(): AHT20
|
||||||
|
{
|
||||||
|
const buf = pins.createBuffer(3);
|
||||||
|
buf[0] = 0xac;
|
||||||
|
buf[1] = 0x33;
|
||||||
|
buf[2] = 0x00;
|
||||||
|
pins.i2cWriteBuffer(this._Address, buf, false);
|
||||||
|
basic.pause(80);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetState(): { Busy: boolean, Calibrated: boolean }
|
||||||
|
{
|
||||||
|
const buf = pins.i2cReadBuffer(this._Address, 1, false);
|
||||||
|
const busy = buf[0] & 0x80 ? true : false;
|
||||||
|
const calibrated = buf[0] & 0x08 ? true : false;
|
||||||
|
|
||||||
|
return { Busy: busy, Calibrated: calibrated };
|
||||||
|
}
|
||||||
|
|
||||||
|
public Read(): { Humidity: number, Temperature: number }
|
||||||
|
{
|
||||||
|
const buf = pins.i2cReadBuffer(this._Address, 7, false);
|
||||||
|
|
||||||
|
const crc8 = AHT20.CalcCRC8(buf, 0, 6);
|
||||||
|
if (buf[6] != crc8) return null;
|
||||||
|
|
||||||
|
const humidity = ((buf[1] << 12) + (buf[2] << 4) + (buf[3] >> 4)) * 100 / 1048576;
|
||||||
|
const temperature = (((buf[3] & 0x0f) << 16) + (buf[4] << 8) + buf[5]) * 200 / 1048576 - 50;
|
||||||
|
|
||||||
|
return { Humidity: humidity, Temperature: temperature };
|
||||||
|
}
|
||||||
|
|
||||||
|
private _Address: number;
|
||||||
|
|
||||||
|
private static CalcCRC8(buf: Buffer, offset: number, size: number): number
|
||||||
|
{
|
||||||
|
let crc8 = 0xff;
|
||||||
|
for (let i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
crc8 ^= buf[offset + i];
|
||||||
|
for (let j = 0; j < 8; ++j)
|
||||||
|
{
|
||||||
|
if (crc8 & 0x80)
|
||||||
|
{
|
||||||
|
crc8 <<= 1;
|
||||||
|
crc8 ^= 0x31;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crc8 <<= 1;
|
||||||
|
}
|
||||||
|
crc8 &= 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc8;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
114
test.ts
114
test.ts
@ -1,104 +1,12 @@
|
|||||||
// grove.onGesture(GroveGesture.Up, () => {
|
let _4Digit = grove.createDisplay(DigitalPin.C16, DigitalPin.C17)
|
||||||
// basic.showString("U")
|
grove.setupWifi(
|
||||||
// })
|
SerialPin.P15,
|
||||||
// grove.onGesture(GroveGesture.Down, () => {
|
SerialPin.P1,
|
||||||
// basic.showString("D")
|
BaudRate.BaudRate115200,
|
||||||
// })
|
"test-ssid",
|
||||||
// grove.onGesture(GroveGesture.Right, () => {
|
"test-passwd"
|
||||||
// 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")
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.Right, AnalogPin.P0,AnalogPin.P1, () => {
|
basic.forever(function () {
|
||||||
// // basic.showArrow(ArrowNames.East);
|
_4Digit.bit(6, 1)
|
||||||
// basic.showString("1");
|
})
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.Left, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.West);
|
|
||||||
// basic.showString("2");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.Up, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.North);
|
|
||||||
// basic.showString("3");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.Down, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.South);
|
|
||||||
// basic.showString("4");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.UL, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.NorthEast);
|
|
||||||
// basic.showString("5");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.UR, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.NorthWest);
|
|
||||||
// basic.showString("6");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.LL, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.SouthWest);
|
|
||||||
// basic.showString("7");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.LR, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// // basic.showArrow(ArrowNames.SouthEast);
|
|
||||||
// basic.showString("8");
|
|
||||||
// })
|
|
||||||
|
|
||||||
// grove.onJoystick(GroveJoystickKey.Press, AnalogPin.P0,AnalogPin.P1, () => {
|
|
||||||
// basic.showString("9");
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
// let p : grove.PAJ7620;
|
|
||||||
// p.init();
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
// display.show(data ++);
|
|
||||||
// let distance = grove.measureInCentimeters(DigitalPin.P0);
|
|
||||||
basic.showNumber(12);
|
|
||||||
basic.pause(2000);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user