Hi Sébastien,
Sorry first chance I have had to reply. Could you dumb this down some more for me please, I have tried for a few hours to adapt your example but still no joy.
I have a uno connected to i2c to an oled to display, code below
Sorry if this is very basic to some (most) people and I should have provided my code to begin with.
So no function already built in to provide the results in meters & centimetres, just centimetres only Serial.println(myLidarLite.distanceContinuous());
Any help would be very appreciated !
(A) My current working CM code that I understand (I am a beginner) (gets the data and puts it into 2 nice boxes on the oled, I just want meter as output)
#include "U8glib.h"
#include <Wire.h>
#include <LIDARLite.h>
LIDARLite myLidarLite;
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
void setup(void) {
Serial.begin(115200);
myLidarLite.begin();
}
void loop() {
Serial.println(myLidarLite.distanceContinuous());
// picture loop
u8g.firstPage();
do {
u8g.setContrast(128 );
// u8g.drawRFrame(0, 0, 84, 17, 3); //Data1 frame
// u8g.drawRFrame(51, 16, 33, 10, 3); //Data1 label frame
u8g.drawRFrame(0, 0, 126, 64, 3); //Outside Frame
u8g.drawRFrame(0, 0, 126, 30, 3); //Title label frame
u8g.drawRFrame(0, 31, 126, 33, 3); //Data frame
u8g.setFont(u8g_font_10x20);
// u8g.drawStr(55, 24, "Data1");
u8g.drawStr(18, 18, "Distance");
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(2, 15);
// u8g.print(thisMicros - lastMicros);
u8g.setPrintPos(22, 52);
u8g.print(myLidarLite.distance());
u8g.print(" cm");
} while( u8g.nextPage() );
delay(1000);
}
(B) Not working Meter code
Many many attempts but now I seem to be stuck with “I was not declared in this scope” but is this not declaring it? for(int i = 0; i < 11; i++); (I think this line means keep looping up to 11 times but that’s it sorry)
#include "U8glib.h"
#include <Wire.h>
#include <LIDARLite.h>
LIDARLite myLidarLite;
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
// Returns the number of integral meters from a distance in centimeters
int getMeters(int distanceInCM)
{
return (distanceInCM / 100);
}
// Returns the number of centimers (< 100) from a distance in centimeters
int getCM(int distanceInCM)
{
return (distanceInCM % 100);
}
void setup(void){
Serial.begin(115200);
myLidarLite.begin();
}
void loop() {
for(int i = 0; i < 11; i++);
Serial.print(getMeters(myLidarLite.distance));
// picture loop
u8g.firstPage();
do {
u8g.setContrast(128 );
// u8g.drawRFrame(0, 0, 84, 17, 3); //Data1 frame
// u8g.drawRFrame(51, 16, 33, 10, 3); //Data1 label frame
u8g.drawRFrame(0, 0, 126, 64, 3); //Outside Frame
u8g.drawRFrame(0, 0, 126, 30, 3); //Title label frame
u8g.drawRFrame(0, 31, 126, 33, 3); //Data frame
u8g.setFont(u8g_font_10x20);
// u8g.drawStr(55, 24, "Data1");
u8g.drawStr(18, 18, "Distance");
u8g.setFont(u8g_font_10x20);
u8g.setPrintPos(2, 15);
// u8g.print(thisMicros - lastMicros);
u8g.setPrintPos(22, 52);
u8g.print(myLidarLite.distance());
u8g.print(" cm");
} while( u8g.nextPage() );
delay(1000);
}