DFROBOT GP8302 Javascript function with I2Coutput node

Hi there. If you need to drive a GP8302 (Digital to analog current converter), here is the code i wrote with the help of chagpt after few hours of tries. in a javascript function in the dashboard with I2C nodes.
==============================
var value = msg.payload;
value = Math.max(0, Math.min(0xFFF, value)); // Clamp value between 0 and 0xFFF
var lsb4 = value & 0xF; // Least significant 4 bits
var msb8 = (lsb4 << 4); // Shift the least significant bits to the left to occupy the first 4 bits
var byte1 = (value >> 4) & 0xFF; // Most significant bits
var result = (byte1 << 8) | msb8;
msg.payload = result;
return msg;
=========================
You need to set the I2C Ouput
Adresse 88
Command 2
Bytes 3
I used it with a slider from 0 to  4095 and a 470 ohms resistor wired on the output of the device. The current goes from 0 to 20ma
Hope this useful :slight_smile: