Hi! I have a problem when using Homeyduino and using dim capibility. When I use the function Homey.value.toFloat(); It only sends me back 0.00 or 1.00. When I adjust the dimmer in the Homey app I can see it sends a new value every time only it’s always 0.00 until i drag the dimmer to the top and it sends me 1.00. Does anyone now what I’m doing wrong?
Hi Mathias, welcome to this community forum.
Can you please show the relevant peace of your code, how else can we see what is wrong?
Yes of course sorry. Wrote on my phone and didn’t have the code.
void setup()
{
Serial.begin(115200);
pinMode(LED, OUTPUT);
Homey.begin(“Jysk3”);
Homey.setClass(“light”);
Homey.addCapability(“onoff”, setState);
Homey.addCapability(“dim”, setDim);
Homey.addAction(“LED”, setState);
Homey.addAction(“DIM_LED”, setDim);
Homey.addCondition(“state”, getState);
//Homey.addCondition(“dim”, getDim);
}
//-----------------------------------------------------------------------
void loop()
{
Homey.loop();
}
//-----------------------------------------------------------------------
void setState() {
state = Homey.value.toInt();
applyState();
}
void setDim()
{
dim_level = Homey.value.toFloat();
dim_level = map (dim_level, 0.00, 1.00, 0, 255);
Serial.println(dim_level);
applyDim();
}
void applyState() {
digitalWrite(LED, state);
Homey.setCapabilityValue(“onoff”, state);
Homey.trigger(“state”, state);
}
void applyDim(){
analogWrite(LED, dim_level);
Homey.setCapabilityValue(“dim”, dim_level);
Homey.trigger(“dim_level”, dim_level);
}
void getState() {
Serial.println("getState(): state is "+String(state));
return Homey.returnResult(state);
}
https://www.arduino.cc/reference/en/language/functions/math/map/:
As previously mentioned, the map() function uses integer math.
So you need to write your own mapping function that can handle floats.
Thanks a lot!!! That did the trick!
Hi, Can you share the full working code?