Making an object rotate

I am trying to make a fan spin when a tags value is one and stop spinning when it is 0. I have a script that runs on startup and it works however once the value is changed the script no longer works (the fan won't stop). Is there a better way to do this? Thanks!

I would do this with CSS and a tag binding -- no script. Can you post your script as a starting point?

2 Likes
1 Like

Here is the scrip this far.

Yeah, don't do that.

  1. time.sleep() is evil in Ignition. Anytime you're using it, you are almost certainly doing something wrong.
  2. with a for loop inside of a while loop, you will see long delay's between when the tag value changes to 0 and when the spinning actually stops, because the for loop must complete execution before the while loop examines it's loop condition again. Potentially 8.75 seconds of delay (due to the time.sleep() commond), on top of normal network latency.
  3. Once you've read the tag, you are never updating the 'spin' variable, which means this is an infinite loop (a.k.a. memory leak). Once you're in the loop, you will never exit.

The better way to do this is with an expression binding and a CSS class.

3 Likes

Thanks! Could you give me an example of how to do that?

Define the animation in your CSS stylesheet.

Create a property called animation under your fan's style properties.

image

Click the binding icon (left side of that highlight above) and use a tag binding to the Manufacturing Cooling Fan 3 tag that you have.

Add a map transform that returns the name of the animation you defined in your CSS stylesheet when the value of the tag is 1, otherwise return an empty string.

3 Likes

I much prefer to create style classes for things like this so that they're selectable, rather than having to look up or remember what options you've got. You can extend the class in the stylesheet if you need

3 Likes

One change I'd suggest is skipping the transform since it's pretty straightforward to do it all in an expression instead:

if({path/to/tag}, 
   "css_class_name", 
   "")
4 Likes