Recieving analog data from IRsensor and sending I2C to a driver

Hi, Im new to the arduino world, and I need some help... Im making a new project, I want to read distance from an IR sensor and change the focus of a liquid lens that maches the distance. I am using arduino nano v3.1. I connected it to a sharp 2y0a21 IR sensor to read distance from an object so far everything works fine, I connected it to a liquid lens driver (HV892) and used a i2c scanner library to read its address (0x23). I dont know how to write the code that maches every cm I read from the sensor to every voltage I want to send to the driver of the liquid lens.

Tnx in advance,


We have no idea how to solve your problem because we can't see it. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. Or perhaps open it in WordPad, which isn't very good for looking at code. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Many questions can be answered by reading the documentation which is provided with the IDE, available under the help tab, or online here.

You have to take into account your lens characteristics. Have data sheets?