forked from PulsedLight3D/LIDARLite_v2_Arduino_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PWM.ino
31 lines (25 loc) · 1.09 KB
/
PWM.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* =============================================================================
LIDAR-Lite v2: PWM operation
This example demonstrates how to read measurements from LIDAR-Lite v2 "Blue
Label" using PWM
The library is in BETA, so subscribe to the github repo to recieve updates, or
just check in periodically:
https://github.com/PulsedLight3D/LIDARLite_v2_Arduino_Library
To learn more read over lidarlite.cpp as each function is commented
=========================================================================== */
unsigned long pulse_width;
void setup()
{
Serial.begin(115200); // Start serial communications
pinMode(2, OUTPUT); // Set pin 2 as trigger pin
pinMode(3, INPUT); // Set pin 3 as monitor pin
digitalWrite(2, LOW); // Set trigger LOW for continuous read
}
void loop()
{
pulse_width = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds
if(pulse_width != 0){ // If we get a reading that isn't zero, let's print it
pulse_width = pulse_width/10; // 10usec = 1 cm of distance for LIDAR-Lite
Serial.println(pulse_width); // Print the distance
}
}