Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f55133bc27 | ||
|
|
717b846846 | ||
|
|
96df6b18b2 | ||
|
|
c64162453a | ||
|
|
fa4ff3da22 |
63
main.ts
63
main.ts
@@ -452,7 +452,68 @@ namespace grove {
|
|||||||
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
|
// 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
|
||||||
@@ -804,4 +865,4 @@ namespace grove {
|
|||||||
function sendAtCmd(cmd: string) {
|
function sendAtCmd(cmd: string) {
|
||||||
serial.writeString(cmd + "\u000D\u000A")
|
serial.writeString(cmd + "\u000D\u000A")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
pxt.json
2
pxt.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Grove",
|
"name": "Grove",
|
||||||
"version": "0.3.0",
|
"version": "0.4.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": {
|
||||||
|
|||||||
Reference in New Issue
Block a user