-
Hello, the sensor works when you press the RAM key, but when you enter save() in the left window, and disconnect the device from the power supply and reconnect (com), it gives an error:
in function called from system
Uncaught Error: I2C device not responding
at line 1 col 24
this.i2c.writeTo(41,179);var a=this.i2c.readFrom(41,9);if(a[...
^
in function "getValue" called from line 12 col 34
var color = colorSensor.getValue();^
What to do, how to continue reading data to the console again after restarting the power supply?
The code I used is as follows:PrimaryI2C.setup({sda: SDA, scl: SCL, bitrate: 100000});
var colorSensor = require("TCS3472x").connect(PrimaryI2C, 1, 1);
var PIN_BACKLIGHT = P5;
digitalWrite(PIN_BACKLIGHT, true);
setInterval(function() {
var color = colorSensor.getValue();
var r = Math.floor(color.red / color.clear * 255);
var g = Math.floor(color.green / color.clear * 255);
var b = Math.floor(color.blue / color.clear * 255);if ((r > g) && (r > b))
print("RED");
else if ((g > r) && (g > b))
print("GREEN");
else if ((b > g) && (b > r))
print("BLUE");
}, 100);
// d-sda, c-scl, g-gnd, v-vin, l-P5
Great! the actual library that gets loaded automatically is http://www.espruino.com/modules/TCS3472x.js