using while and loop and variable in Macro
-
@fcwilt
The heating is not on ... or there is not even one installed. Only one temperature sensor is connected.How can I display, for check, the result of sensors.analog[0].lastReading ???
is this the right value? rounding in dwc I see 23°C
-
@crazycreator said in using while and loop and variable in Macro:
@fcwilt
The heating is not on ... or there is not even one installed. Only one temperature sensor is connected.How can I display, for check, the result of sensors.analog[0].lastReading ???
right before the line containing the while put this:
echo sensors.analog[0].lastReading
It will display a message showing the value. While the message will go away after a few seconds you can still see the result in the DWC Console.
Frederick
-
@fcwilt said in using while and loop and variable in Macro:
echo sensors.analog[0].lastReading
i See the message in dwc but this is the only thing.
my macro:
; R=Red / U=Green / B=Blue / P=Brightness (0-255) M150 X1 ; Define RGB NeoPixel (default in RRF 3.2 and later) var counter = 150 var down = true echo sensors.analog[0].lastReading while sensors.analog[0].lastReading < 40 if var.down set var.counter = var.counter-1 M150 R255 U0 B0 S20 P<var.counter> F0 if var.counter == 255 set var.down = true else set var.counter = var.counter+1 M150 R255 U0 B0 S20 P<var.counter> F0 if var.counter == 0 set var.down = false G4 P100
When I change P<var.counter> to P155 the script is running actually endless
and always in the same if ....I think the variable var.counter will not be changed.
because if I change var down = true and var.down = false then it changes from the if to the else but it then gets stuck in it.
-
If the while loop is not ending it is either because the sensor reading is not changing OR the firmware does not update the sensor reading in a while loop.
You could put code in daemon.g but that only runs once every 10 seconds.
Frederick
-
@fcwilt
But that would be strange if the while loop only continues when the value of the sensor has changed.the condition says if the value is less than 40 then run.
-
@crazycreator said in using while and loop and variable in Macro:
@fcwilt
But that would be strange if the while loop only continues when the value of the sensor has changed.the condition says if the value is less than 40 then run.
What was the value displayed by the echo statement when you ran the macro?
Frederick
-
@fcwilt 23
while sensors.analog[0].lastReading < 40 if var.down set var.counter = var.counter-1 M150 R255 U0 B0 S20 P<var.counter> F0 echo var.counter if var.counter == 0 set var.down = false else set var.counter = var.counter+1 M150 R255 U0 B0 S20 P<var.counter> F0 **echo var.counter** if var.counter == 255 set var.down = true G4 P50
if I write an echo IN the loop and display the value of var.counter, then the outputs are perfectly counted. exactly as it should be, but the light does not come on.
if instead of P <var.counter> a fixed number is written in, the light goes on ... but then of course it doesn't breathe
if P <var.counter> the correct spelling?
-
@crazycreator Values passed to a macro are found using "param." parameter letter. So, if the macro was called with P155, you would access the value as param.p. You could do this in the beginning of your macro:
If exists(param.p) Set var.value = param.p Else Set var.value = 150
Use var.value in the body of your macro.
Does that help ?
-
-