Syntax question regarding var and calculation with it

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Syntax question regarding var and calculation with it

#1 Post by chromo23 » 22 Mar 2021, 11:46

Hi,

can i use variables as a trigger like:

Code: Select all

On var#1 do
or

Code: Select all

On var#1=1 do
Couldn’t find an answer to it yet

And calulations are done like this i thought:

Code: Select all

if [ai#Analog] > [var#5] - 100
but i didn´t work like this....(or i did somerwere else a mistake)

On this way i want to show my recent project and thank all the people here that made it softwarewise possible:

It’s called MuFuDi (MultifuncionalDisplay)
It has two tm1637modules and a ldr for dimming the brightness of the displays in the front when it gets dark.
Also a touchbutton sits on top to switch between different modes (eg: shortpress for showing values of different nodes and longpress activates the nightlightfunktion)
inside is a triple ws2812 led-module for the night light as a visual status feedback. (it glows red when humidity reaches a certain level)
a bme280 sits in the foot...
IMG_8295.jpg
IMG_8295.jpg (121.34 KiB) Viewed 3810 times
IMG_8296.jpg
IMG_8296.jpg (122.3 KiB) Viewed 3810 times
IMG_8293.JPG
IMG_8293.JPG (39.55 KiB) Viewed 3810 times
img231.png
img231.png (469.94 KiB) Viewed 3810 times
GIF-2021-03-22-11-38-21.gif
GIF-2021-03-22-11-38-21.gif (3.54 MiB) Viewed 3796 times
Last edited by chromo23 on 22 Mar 2021, 12:49, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Syntax question regarding var and calculation with it

#2 Post by TD-er » 22 Mar 2021, 11:51

When calculations (often in compares like an if-statement) you should try to store it first in a variable using the let command

Code: Select all

let,15,[var#5] - 100
if [ai#Analog] > [var#15]

Variable updates never trigger an event, so "On var#1=1 do" will not work.
If you need to handle an event on a variable update, you should call an event with an event name you made up yourself
Preferrably use "asyncevent" and not "event" as it will then added to the event queue and dealt with later.
When using "event" it will be executed immediately and thus consume a lot more resources (especially if that event handler also triggers an event, etc)


Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests