Created
March 8, 2015 19:10
-
-
Save murphysean/aa70383a575a2cc56d9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#define LIDARLite_ADDRESS 0x62 // Default I2C Address of LIDAR-Lite. | |
#define RegisterMeasure 0x00 // Register to write to initiate ranging. | |
#define MeasureValue 0x04 // Value to initiate ranging. | |
#define RegisterHighLowB 0x8f // Register to get both High and Low bytes in 1 call. | |
int reading = 0; | |
// the setup function runs once when you press reset or power the board | |
void setup() { | |
Wire.begin(); | |
// initialize digital pin 13 as an output. | |
pinMode(13, OUTPUT); | |
pinMode(7, INPUT); | |
Serial.begin(9600); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
Wire.beginTransmission((int)LIDARLite_ADDRESS); | |
Wire.write((int)RegisterMeasure); | |
Wire.write((int)MeasureValue); | |
Wire.endTransmission(); | |
delay(20); | |
Wire.beginTransmission((int)LIDARLite_ADDRESS); | |
Wire.write((int)RegisterHighLowB); | |
Wire.endTransmission(); | |
delay(20); | |
Wire.requestFrom((int)LIDARLite_ADDRESS,2); | |
if(2 <= Wire.available()){ | |
reading = Wire.read(); | |
reading = reading << 8; | |
reading |= Wire.read(); | |
Serial.print("laser-cm:"); | |
Serial.println(reading); | |
} | |
int sensorValue = analogRead(A1); | |
int ainches = sensorValue/2; | |
float voltage = sensorValue * (5.0 / 1023.0); | |
long pulse = pulseIn(7, HIGH); | |
long inches = pulse/147; | |
Serial.print("sonar-pw-inches:"); | |
Serial.println(inches); | |
Serial.print("sonar-a-inches:"); | |
Serial.println(ainches); | |
//Serial.print("avolts:"); | |
//Serial.println(voltage); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment