Can LUA code make this switch work?

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

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

Re: Can LUA code make this switch work?

#11 Post by Kaellis991 »

When you guys think / talk / write about this HIGH LOW concept, do you actually picture some sort of image in your mind?
Whenever I discuss the design and detailing of a building, I form mental images of the physical reality to help me understand the ideas.
Then I translate those ideas into drawings to help explain to others. A picture is worth....as they say.

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Can LUA code make this switch work?

#12 Post by Ralph »

Great! I recommend removing the prints when you're going to finally use it.
A normal on off switch is probably easy. But if you want then I can add an example for this as well.

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

Re: Can LUA code make this switch work?

#13 Post by Kaellis991 »

Ralph wrote: Fri Sep 16, 2022 10:06 am Great! I recommend removing the prints when you're going to finally use it.
A normal on off switch is probably easy. But if you want then I can add an example for this as well.
Ralph,

I will remove the print lines.

An example for this would help because here is where I am getting stumped.
All of the hardware switches I have found to download for cloning use an Xplane Command that have an ...._ON or ...._OFF command.

This DME switch is a dataref that is changed by setting the INT value to 0 or 1.

I can't find any downloadable hardware switches that are using datarefs with the integer values for on and off.

My 2-way switch also has the same 3 terminals as the 3 position switch.

image.png
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Can LUA code make this switch work?

#14 Post by jph »

Kaellis991 wrote: Fri Sep 16, 2022 9:49 am When you guys think / talk / write about this HIGH LOW concept, do you actually picture some sort of image in your mind?
Whenever I discuss the design and detailing of a building, I form mental images of the physical reality to help me understand the ideas.
Then I translate those ideas into drawings to help explain to others. A picture is worth....as they say.
I can only speak for myself but I visualise - I suppose - binary... simply high or low / true of false - mainly , I tend to think in terms of 1 and 0 (ones and zeros though) as most of the stuff I am doing at the moment is stuffing bits into bytes and words and examining them and shifting them.

It comes from programming in machine code on the Z80 in the 1970's before we had an assembler which is an assembly language program to convert op codes to 'machine' code ! - all hand coded in Z80 op codes and then manually converted to binary / hex and entered by hand - until an assembler came along - and you could afford it !, Even then you were working directly in binary / byte level, also with PIC micros where we work at the register level so again, all binary and bit setting bu that is easy-peasy on 8 bit micros until you get to pages and switching on 6502 micros etc but hey.

As the old saying goes, there are 10 types of people in the world who understand Binary. those that do and those that don't :)

It just seems perfectly natural. (to me)
When you had to work with logic IC's such as the 74 and 4000 series you rapidly became conversant with Boolean algebra as well.
They are all fancy words but all fairly simple concepts to grasp really - once you know what it is of course.

At the moment, as an example, I am working with a 40 year old design called a 4067 multiplexor, which is basically a very cheap solid state analogue / digital switch. 16 way. so 16 connections with 1 output - which can be used as an input or an output. It is an analog of a 16 position rotary switch but on a tiny scale.
4 input pins control which of the 16 pins are connected to the IO pin. 4 bits in binary give a possible 16 combinations so by stepping through the combinations with 4 pins of the micro connected to the 4 inputs on the multiplexor the correct 1 of 16 pins can be connected to the single IO pin. If you do this rapidly enough then you can read 16 inputs on a single pin very easily. By rapid, I am talking around a million times a second, which is what the chip is capable of so I have to slow the process down to its level haha. But, the 4 control inputs are just simple switches themselves in my mind, they are nothing but ones and zeros.
I think about your switch in the same way - what can it offer in terms of inputs, in this case, two. So, now how can I use them - as mentioned before, 4 possible logical states of the 2 bits but only 3 physically due to the switch, so we can have 3 actions depending on the position of the 2 inputs, hence the position of the switch.

You sort of need to get away from the ,,,,,, "I have a live feed here, and a ground here, and if I connect this to a supply and put a bulb in, then a switch can be used to control the bulb etc etc. That is the 'electro mechanical' aspect of the switch and it's normal usage, but here, all we are interested in is how many 'states' the switch or whatever can be in.

You are also seeing a lot of terms that are from so long ago but are in common usage, like pull ups and pull downs, that are not intuitive at all without context.

When we started using CMOS logic - the 4000 series mainly, then the 'input' on a pin goes to a FET unit (MOSFET) which effectively draws no current - well, apart from charging the gate capacitance. It is also extremely high input impedance, often 10's of megaohms. These are so sensitive that you can turn them on and off by simply touching them, even via a couple of megaohm resistor. The input has to be a 1 or a 0 (HIGH or LOW, TRUE or FALSE) - which mean the same for this simple exercise.
There is a threshold at which the level changes, it might be, anything below 0.7V is a 0, and anything above 2V is a 1, but the area in the middle is called the floating area and the pin can arbitrarily adopt a logic state as it has no reference if not referenced to something. It has to be one or the other or the circuit will have a hissy fit so someone coined the term that any UNUSED pins MUST be 'tied up to VDD', or 'tied down to VSS' (read VCC and GND for ease of use). So you will here terms like 'tied to VCC' or 'tied to ground' etc.
Then, when the pin is actually in use, it cannot be allowed to have a 'floating' value at any time, so we need a similar thing, but not 'tied' as that is fixed. so the term 'PULLED UP' and 'PULLED DOWN' were used as they followed from tied. As they needed to be able to change state and couldnt be physically TIED then the way to do it was to use a PULL UP resistor, or indeed, a PULL DOWN resistor. Then the in was always at a known level but could be over-ridden as the resistor would act as the compensator and drop the voltage when the state changed.

Even the term 'bug' in a program / computer comes from a literal 'bug' (bugs) that used to short out the connections in the thermionic valve bases (Tubes to you yanks lol)
So, there were actually REAL bugs in computers...

You will come across other terms that have nothing to do with electronics per se but are in common use - a 'boot strap' driver for instance.. more of a joke reference to an impossible scenario where people should 'pull themselves up by their bootstraps' - which of course is not possible, but a device that does the seemingly impossible - called a high side mosfet bootstrap driver - adopted the name.

A lot of the terms are from people with a sense of humour - the 'bit' was first, then a collection of bits (8) was a byte (as opposed to bite but it was a suitable reference)
When working in hexadecimal for instance, then a byte is 2 lots of 4 bits. What can we call 'half a byte' ? - well, if you only have half a byte then you only had a nibble haha.. and that is exactly what it is called today. A nibble is 4 bits.

You are into boats aren't you ? - think how many terms in Nautical usage are from everyday things, and yet few understand them.. and evenbetter - how many nautical terms make up the English language ! :shock: :o answer - a hell of a lot. !!

It's plain sailing ! - meaning easy enough - but

yeah, but it's not historically, the term is PLANE sailing (although many a ships master could not spell so 'plain' was also used incorrectly), referring to a PLANE of a right angled triangle used to determine position over short distances. Its a long time since I did my Yacht Master cert though ;)

-
anyway, doing what you are doing now, physically hooking up to a board and bashing some code in and out is the very best you can do as it allows you to change thins and actually see the results before your eyes with well timed print statements or other feedback. Keep at it, I think you are doing great.

Joe
Joe. CISSP, MSc.

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

Re: Can LUA code make this switch work?

#15 Post by Kaellis991 »

Joe,

Many of those hysterical...er....historical terms I have gleamed over the 38 year span I have been working with computers. That experience has been mostly on the hardware side of connecting networks, building PCs and on the software side just installing programs. Learned about the origin of the term bug many years ago.
Back in the mid 70s I had some introduction to punch cards at UT Austin when Michael Dell was selling computers from his trunk at a nearby dormitory. but it never went any further than programming some building specifications.
That is information which has long since vanished from my synapses.

Programming languages were and always have been difficult but the electrical-mechanical side was always easier because I could form a clear 3D image in my mind. Could never do that with languages.
Thanks for sharing that information. Very helpful stuff...

In terms of bashing out code, I have been trying to figure out how to change the 3-way switch code to a simple ON/OFF switch, but can't really figure out what to keep, what to remove and what to change in that script.
Right now I am just bashing it around with a sledge hammer in an effort to understand the logic.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Can LUA code make this switch work?

#16 Post by jph »

:D those were the days eh?

As for the on off, if its the same switch body but just slides on way or the other then you need 1 input pin only, and the wiring is middle pin on 1 side to gnd and either of the ends on the same side to the pin, ignore the others as electromechanically the switch looks to be configured as a simple dpdt
You just use it in SPST mode.

for the code, 1 input only, do something when low, nothing else needed, unless you need an action when electrically off? in that case do something when high. On and off is a concept only as far as the code is concerned. You can tell the code the switch is 'off' when it is electromechanically on and on when it is electromechanically off. Simply a matter of - if mechanically off, then when pin is high you can say that that is classed as on in your code, and when mechanically on and it pulls the pin low, you can tell your code that that is 'off'


Joe
Last edited by jph on Fri Sep 16, 2022 4:53 pm, edited 1 time in total.
Joe. CISSP, MSc.

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

Re: Can LUA code make this switch work?

#17 Post by Kaellis991 »

jph wrote: Fri Sep 16, 2022 4:13 pm :D those were the days eh?

As for the on off, if its the same switch body but just slides on way or the other then you need 1 input pin only, and the wiring is middle pin on 1 side to gnd and either of the ends on the same side to the pin, ignore the others as electromechanically the switch looks to be configured as a simple dpdt
You just use it in SPST mode.

for the code, 1 input only, do something when low, nothing else needed, unless you need an action when off? in that case do something when high also.

Joe
I will give that a try. My attempts at scripting is analogous to this....

Keith said he was going to go through, step by step, a code like this one to explain what all the lines are actually doing, but he is indisposed for a couple of weeks, so I will have to wait on that.
image.png
Last edited by Kaellis991 on Fri Sep 16, 2022 4:59 pm, edited 1 time in total.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Can LUA code make this switch work?

#18 Post by jph »

:lol:
When I am coding in Arduino IDE I usually have 7 or 8 sketches (code windows) open so I just copy and paste my old code as otherwise I forget what it means and cant be bothered to read the comments I added :roll:
Very similar to painting by numbers. :D
Joe. CISSP, MSc.

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

Re: Can LUA code make this switch work?

#19 Post by Kaellis991 »

jph wrote: Fri Sep 16, 2022 4:56 pm :lol:
When I am coding in Arduino IDE I usually have 7 or 8 sketches (code windows) open so I just copy and paste my old code as otherwise I forget what it means and cant be bothered to read the comments I added :roll:
Very similar to painting by numbers. :D
That makes sense but you know what pieces you need and what they do.
Perhaps when Keith can get back in the loop, he might be able to explain these lines of code, what they mean and what they do.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Can LUA code make this switch work?

#20 Post by jph »

You will quickly find that most coding is very very repetitive.
You tend to re-use old code over and over or simply change a few lines.

I mean, if you have 100 buttons or inputs, then the code to read 100 buttons is fairly simple and what you do with the 100 buttons and the state and logic comparisons is simply a long list.
A HELL OF A LOT of code that you may see is very nicely thinned down to the minimal amount, but there is absolutely no need to do that at all.
There is nothing stopping you having hundreds of if - then - else if you want to. Yes, there may be some nice tricks and syntax options, but it doesn't matter in the slightest at the end of the day.

Most really 'compact' code is absolutely THE most difficult to understand, often for the writer in a couple of weeks.... GOOD code is code that works. That's it.
Joe. CISSP, MSc.

Post Reply