expected unqualified-id before '.' token error

I was trying to fix a I2C hang error cause by using the Wire.h library. I tried a new library called I2C.h but I got the error expected unqualified-id before ‘.’ token error for every I2C. line. Can you guys help me fix the problem. Thanks in advance :slight_smile:
P/s: I’m using Lidar v2 lite from garman to render a 3D map, but I’m new to point cloud and coding. I heard you can render it with Unity3D… Any chance you guys know how to do it as well?

#include <I2C.h>
#include <LIDARLite.h>
#include <MsTimer2.h>
#include <AccelStepper.h>
#include <Servo.h>
#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.
#define HALFSTEP 8
#define FULLSTEP 4
#define blue 9
#define pink 10
#define yellow 11
#define orange 12

int distance = 0;
float fdistance;
int angleScan = 0;
int angleRotate = 0;
int Rotate = 0;
int targetPosition = 2048; // 2048 for 1 full circle
int roundCount=0;
bool clockwise = true;

AccelStepper stepper(8, 2, 4, 3, 5);
Servo servo;
LIDARLite myLidarLite;

void setup()
{
I2C.begin();
delay(100);
I2C.timeOut(50);
Serial.begin(115200);
servo.attach(8);
stepper.setMaxSpeed(1000);
myLidarLite.begin(0,true);

//Moving to initial position
stepper.moveTo(targetPosition);
stepper.setSpeed(650);
servo.write(angleScan);
}

void loop()
{
if (angleScan <=90)
{
angleRotate=stepper.currentPosition()*360/2048;
servo.write(angleScan);
printOutput(angleRotate,angleScan,distance);
if(stepper.distanceToGo()==0)
{
stepper.setCurrentPosition(0);
stepper.moveTo(targetPosition);
stepper.setSpeed(650);
if (roundCount=2) // when system revolve 2 times, elevate the Lidar by 1
{
roundCount=0;
angleScan = (angleScan + 1);
servo.write(angleScan);
}
}
stepper.runSpeed();
}
return;
}

void printOutput(int angleRotate, int angleScan, int distance)
{
static unsigned long timer = 0;
unsigned long interval = 10; //1 samples every 10 ms
if (millis() - timer > interval)
{
timer = millis();
// myLidarLite.beginContinuous(false,0x13,0xff,0x62); //100Hz, infinite reading
// distance = myLidarLite.distanceContinuous();
getdistance();
if(distance>1300)
{
distance-=1300;
}
fdistance = (distance*1.008 - 14.18);
if (fdistance<0)
{
fdistance = 0;
}
Serial.print(“T”);
if (angleRotate < 10)
Serial.print(“00”);
else if (angleRotate < 100)
Serial.print(“0”);
Serial.print(angleRotate);

Serial.print(“P”);
if (angleScan < 10)
Serial.print(“00”);
else if (angleScan < 100)
Serial.print(“0”);
Serial.print(angleScan);

Serial.print(“V”);
if (fdistance < 10)
Serial.print(“000”);
else if (fdistance < 100)
Serial.print(“00”);
else if (fdistance < 1000)
Serial.print(“0”);
Serial.println((int)fdistance);
Serial.flush();
}
}

void getdistance()
{
// Write 0x04 to register 0x00
uint8_t nackack = 100; // Setup variable to hold ACK/NACK resopnses
while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
nackack = I2C.write(LIDARLite_ADDRESS,RegisterMeasure, MeasureValue); // Write 0x04 to 0x00
delay(1); // Wait 1 ms to prevent overpolling
}

byte distanceArray[2]; // array to store distance bytes from read function

// Read 2byte distance from register 0x8f
nackack = 100; // Setup variable to hold ACK/NACK resopnses
while (nackack != 0){ // While NACK keep going (i.e. continue polling until sucess message (ACK) is received )
nackack = I2C.read(LIDARLite_ADDRESS,RegisterHighLowB, 2, distanceArray); // Read 2 Bytes from LIDAR-Lite Address and store in array
delay(1); // Wait 1 ms to prevent overpolling
}
distance = (distanceArray[0] << 8) + distanceArray[1]; // Shift high byte [0] 8 to the left and add low byte [1] to create 16-bit int
}

Because.... "I2C" names a type (i.e. , a class) NOT an instance of that type. You need to create an instance of an object of type I2C.

I2C myI2CMaster = new I2C();
...
myI2C.begin();

Regards,
Ray L.

Read the sticky posts at the top of each forum to see how to post code. Then you won't have smiley faces. And it will be easier for folks to read, etc.

Thank you guys, and I will fix it next time. Sorry if I caused you any trouble