Siminnovations switch example questions

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Siminnovations switch example questions

#1 Post by Kaellis991 »

I had these questions over in another thread but I didnt want them to get buried and lost in the middle of another thread.
If this is not acceptable, then it can be removed.

After reading through the examples for creating the switch hardware, I see many words and sentences in the instructions for which I could use some additional explanation.
As someone with no experience with programming and the terms used, I need some hand-holding to get a layman's understanding of what these words mean in the context of programming.

Here is the Wiki Switch hardware example I am trying to decipher. Can someone elaborate on these questions I have?

1. The use of hw_switch_id= is confusing. Is that optional or not? I think I have seen comments that it is optional but I am not sure where I read that. See additional questions about hw_switch_id below.
2. The sentence... "switch_add is used to add a hardware switch." does not include the hw_ before switch_add as it shows in the previous two lines under description. Is it supposed to be hw_switch_add or simply switch_add?
3. Under Return Value and hw_switch_id there is a sentence "This value can be used for further reference". What does that mean?
4. Further down there is a section called Hardware Id's and a sentence that states "Hardware id's are not preferred, try to use a named hardware instead" is not clear to me. What's the difference between Hardware id's and named hardware? Where does that come into play?
5. Then the next line is also confusing to me. It states "Define the used pin(s) right away. This is Not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script".
I understand how to change the pin assignment when the script is run and the hardware connection pops up to connect the particular arduino, it's channel, and assign the pins. But that instruction above seems to be contradictory. It says to define the pins, but then don't.
6. The last image showing instructions about "Switches are pull up." What does "pull up" mean and how is that done? All of that instruction is vague to me. What does "...is normally pulled to the I/O voltage..." mean? What is pulled to VOLTAGE and GND and how is that done? What software is being referred to?

Sorry for the elementary school questions.

Thanks,
Kirk
image.png
image.png

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Siminnovations switch example questions

#2 Post by Sling »

Hi Kirk,

1 - Yes its optional but its good practice to always use one. Think of it as a name. if you want to refer to/use it later you will need to know its name. The good thing is you get to assign that name(id).

2 - Yes is should have the hw_ at the beginning. But be aware there is also a non hardware switch which is added with switch_add. This is likely just a copy paste error.

3 - See my note in 1 about this being a name. If you want to do something with that switch you need to refer to by this id (name).

4 - Hardware Id's are the actual id's such as ARDUINO_UNO_A_D6 that you can hard code into a Lua script. Named Id's just use a name and generate the hardware assignments selection boxes to which you refer in question 5. This sounds like what you are already using. The reason to use one over the other comes down to the intended use of the particular code. If you plan to share with others you pretty much have to use named hardware because everyone will have different boards and spare pins and can assign the ones they want. I always recommend using the hard coded method if its just for you because there is no risk of the assignments being lost like can happen with named hardware.

5 - Define the used pin(s) right away at the start is all this means. As previously stated this only applies if using named hardware. The pin assignment is done in code for the hardware_id method so is already done.

6 - I can see why this last one is a bit confusing. The switch itself is not pull-up. This refers to the signal lines from the switch to the Arduino. Inside of the Arduino is a resistor on each of the I/O lines that has its other end connected to +V (normally +5V). With nothing connected to the I/O pins these resistors pull the voltage on the I/O lines up to V+. This is a logic 1. To create a logic 0 you ground the appropriate pin. With a switch you ground its common directly to ground and then its other pins will be switched to this ground as you operate the switch.

I've tried to keep these answers basic and simple to understand but be sure to let me know if there is anything you still don't get.

Tony

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Siminnovations switch example questions

#3 Post by Kaellis991 »

Tony,

Thank you for the reply. Your explanantions cleared up a lot about what the examples are describing.
It makes a lot more sense now.

Kirk

Post Reply