Library for the LidarLite, gets distance in cm using the pwm output

Dependents:   LidarLite_test

Fork of MaxbotixDriver by Daniel Casner

Committer:
joe4465
Date:
Wed Mar 18 08:55:54 2015 +0000
Revision:
1:32f0a592b9e5
Child:
2:be66a4cd86c0
V1.0 Works

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe4465 1:32f0a592b9e5 1 #include "LidarLitePwm.h"
joe4465 1:32f0a592b9e5 2
joe4465 1:32f0a592b9e5 3 LidarLitePwm::LidarLitePwm(PinName pin, Timer& timer) : _interrupt(pin), _timer(timer), _pulseStartTime(0), _range(0)
joe4465 1:32f0a592b9e5 4 {
joe4465 1:32f0a592b9e5 5 _interrupt.rise(this, &LidarLitePwm::pulseStart);
joe4465 1:32f0a592b9e5 6 _interrupt.fall(this, &LidarLitePwm::pulseStop);
joe4465 1:32f0a592b9e5 7 }
joe4465 1:32f0a592b9e5 8
joe4465 1:32f0a592b9e5 9 int LidarLitePwm::read()
joe4465 1:32f0a592b9e5 10 {
joe4465 1:32f0a592b9e5 11 return _range;
joe4465 1:32f0a592b9e5 12 }
joe4465 1:32f0a592b9e5 13
joe4465 1:32f0a592b9e5 14 LidarLitePwm::operator int()
joe4465 1:32f0a592b9e5 15 {
joe4465 1:32f0a592b9e5 16 return read();
joe4465 1:32f0a592b9e5 17 }
joe4465 1:32f0a592b9e5 18
joe4465 1:32f0a592b9e5 19 void LidarLitePwm::pulseStart()
joe4465 1:32f0a592b9e5 20 {
joe4465 1:32f0a592b9e5 21 _pulseStartTime = _timer.read_us();
joe4465 1:32f0a592b9e5 22 }
joe4465 1:32f0a592b9e5 23
joe4465 1:32f0a592b9e5 24 void LidarLitePwm::pulseStop()
joe4465 1:32f0a592b9e5 25 {
joe4465 1:32f0a592b9e5 26 int endTime = _timer.read_us();
joe4465 1:32f0a592b9e5 27 if (endTime < _pulseStartTime) return; // Escape if there's been a roll over
joe4465 1:32f0a592b9e5 28 _range = (endTime - _pulseStartTime) / 10; // 10uS per CM
joe4465 1:32f0a592b9e5 29 }