Merge branch 'fork_master'

This commit is contained in:
matsujirushi 2017-10-03 09:19:10 +09:00
commit fd7c606ec2

54
main.ts
View File

@ -102,15 +102,30 @@ namespace grove {
{ {
let duration = 0; let duration = 0;
let RangeInCentimeters = 0; let RangeInCentimeters = 0;
let buf: number [] = [0, 0, 0, 0, 0];
let num = 0;
pins.digitalWritePin(pin, 0); for(let i = 0; i < 5; i ++)
control.waitMicros(2); {
pins.digitalWritePin(pin, 1); pins.digitalWritePin(pin, 0);
control.waitMicros(5); control.waitMicros(2);
pins.digitalWritePin(pin, 0); pins.digitalWritePin(pin, 1);
control.waitMicros(5);
pins.digitalWritePin(pin, 0);
buf[i] = pins.pulseIn(pin, PulseValue.High, 100000); // Max duration 100 ms
}
duration = pins.pulseIn(pin, PulseValue.High); for(let i = 0; i < 5; i ++)
{
if(buf[i] != 0)
{
duration = duration + buf[i];
num ++;
}
}
duration = duration / num;
RangeInCentimeters = duration * 153 / 29 / 2 / 100; RangeInCentimeters = duration * 153 / 29 / 2 / 100;
return RangeInCentimeters; return RangeInCentimeters;
@ -125,15 +140,30 @@ namespace grove {
{ {
let duration = 0; let duration = 0;
let RangeInCentimeters = 0; let RangeInCentimeters = 0;
let buf: number [] = [0, 0, 0, 0, 0];
let num = 0;
pins.digitalWritePin(pin, 0); for(let i = 0; i < 5; i ++)
control.waitMicros(2); {
pins.digitalWritePin(pin, 1); pins.digitalWritePin(pin, 0);
control.waitMicros(5); control.waitMicros(2);
pins.digitalWritePin(pin, 0); pins.digitalWritePin(pin, 1);
control.waitMicros(5);
pins.digitalWritePin(pin, 0);
buf[i] = pins.pulseIn(pin, PulseValue.High, 100000); // Max duration 100 ms
}
duration = pins.pulseIn(pin, PulseValue.High); for(let i = 0; i < 5; i ++)
{
if(buf[i] != 0)
{
duration = duration + buf[i];
num ++;
}
}
duration = duration / num;
RangeInCentimeters = duration * 153 / 74 / 2 / 100; RangeInCentimeters = duration * 153 / 74 / 2 / 100;
return RangeInCentimeters; return RangeInCentimeters;