LUACONTROLLER UNDERSTANDING
LUACONTROLLER UNDERSTANDING
Hi all,
I'm following this tutorial for luacontroller and some things are just not clear to me.
Maybe I do not understand some electronics concepts or how microcontroller works
Can you help me understand it?
Question is:
(from this page: http://mesecons.net/items.html
...
You can easily establish a relation between input and output:
port.b = pin.a
Port B now always adapts the state of port A.
port.a = true port.b = pin.a
The first time this code is executed, port B will stay inactive: Remember, ports are set after the whole code was executed.
However, on a second event, this code will activate port B.
...
I do not understand what this means.
What is the "second event"?
Maybe I do not understand the difference between pin and port?
I have read somewhere that port is like a house door - if you are outside it is an entrance but if you are inside it is an exit. So port are interchangeable but pins are defined...?
Text says:
"However, on a second event, this code will activate port B" ---> how, why - if I turn on pin D then port B activates... is that an event?
When pin.a = true does that mean that port.a is also true? and vice versa?
^_^
I'm following this tutorial for luacontroller and some things are just not clear to me.
Maybe I do not understand some electronics concepts or how microcontroller works
Can you help me understand it?
Question is:
(from this page: http://mesecons.net/items.html
...
You can easily establish a relation between input and output:
port.b = pin.a
Port B now always adapts the state of port A.
port.a = true port.b = pin.a
The first time this code is executed, port B will stay inactive: Remember, ports are set after the whole code was executed.
However, on a second event, this code will activate port B.
...
I do not understand what this means.
What is the "second event"?
Maybe I do not understand the difference between pin and port?
I have read somewhere that port is like a house door - if you are outside it is an entrance but if you are inside it is an exit. So port are interchangeable but pins are defined...?
Text says:
"However, on a second event, this code will activate port B" ---> how, why - if I turn on pin D then port B activates... is that an event?
When pin.a = true does that mean that port.a is also true? and vice versa?
^_^
Love Truth Humility
- Hume2
- Member
- Posts: 710
- Joined: Tue Jun 19, 2018 08:24
- GitHub: Hume2
- In-game: Hume2
- Location: Czech Republic
Re: LUACONTROLLER UNDERSTANDING
Read the chapter 5 to see what is understood as an event. Does it answer your question?
If you lack the reality, go on a trip or find a job.
Re: LUACONTROLLER UNDERSTANDING
Yes, thank you. I have used print( event ) to see what's going on.
Its clear now.
Thank you.
What is still unclear is that - why on a second event, this code (port.a = true port.b = pin.a) will activate port B ?
Love Truth Humility
- Hume2
- Member
- Posts: 710
- Joined: Tue Jun 19, 2018 08:24
- GitHub: Hume2
- In-game: Hume2
- Location: Czech Republic
Re: LUACONTROLLER UNDERSTANDING
It's because at first event, port.a becomes true but pin.a is false so port.b will be also false. On the second run, pin.a becomes true because the mesecon at side A is powered by the luacontroller. So port.b becomes true which activates port B.
If you lack the reality, go on a trip or find a job.
Re: LUACONTROLLER UNDERSTANDING
Thank you Hume2 for the explanation.
What I do not understand still is - what is the difference between pin and port?
Consequently I do not understand why pin.a is not true at the first place - isnt it that mesecon (light) on the side A is powered from the first event (starting the code)? How is it that port is true but pin is false?
Love Truth Humility
- Hume2
- Member
- Posts: 710
- Joined: Tue Jun 19, 2018 08:24
- GitHub: Hume2
- In-game: Hume2
- Location: Czech Republic
Re: LUACONTROLLER UNDERSTANDING
pin and port are two separate variables. When the code starts, the variable pin is filled by the current state of input. At the end of the script, the mesecon signals are turned on or off according to the port variable. The variables pin and port aren't being synchronised throughout the execution unless you explicitly tell it to do so.
If you still don't understand it, you can just skip this example. Just keep in mind that if you set port.a to anything, pin.a will not be affected before the script ends.
If you still don't understand it, you can just skip this example. Just keep in mind that if you set port.a to anything, pin.a will not be affected before the script ends.
If you lack the reality, go on a trip or find a job.
Re: LUACONTROLLER UNDERSTANDING
I got it.Hume2 wrote: ↑Sun Sep 27, 2020 15:58pin and port are two separate variables. When the code starts, the variable pin is filled by the current state of input. At the end of the script, the mesecon signals are turned on or off according to the port variable. The variables pin and port aren't being synchronised throughout the execution unless you explicitly tell it to do so.
If you still don't understand it, you can just skip this example. Just keep in mind that if you set port.a to anything, pin.a will not be affected before the script ends.
Thank you Hume2 :)
Love Truth Humility
Re: LUACONTROLLER UNDERSTANDING
I have come to the similar problem in chapter IV
"Code a timer that toggles port A every two seconds."
My solution is: interrupt (2) port.a = not pin.a
Now - it works, toggles port A every two seconds - until I turn on any other switch on any other port B,C or D - then it starts to blink unevenly and luacontroller overheats.
What am I doing wrong?
"Code a timer that toggles port A every two seconds."
My solution is: interrupt (2) port.a = not pin.a
Now - it works, toggles port A every two seconds - until I turn on any other switch on any other port B,C or D - then it starts to blink unevenly and luacontroller overheats.
What am I doing wrong?
Love Truth Humility
- Hume2
- Member
- Posts: 710
- Joined: Tue Jun 19, 2018 08:24
- GitHub: Hume2
- In-game: Hume2
- Location: Czech Republic
Re: LUACONTROLLER UNDERSTANDING
It's because your code relies on that there are no incoming events, only program and interrupt. Turning on or off the other ports sends the luacontroller more interrupts so the code is being run more times. To avoid this, you need to check if the code was triggered by the event you expected. For example:
if event.type == "program" or event.type == "interrupt" then
port.a = not pin.a
end
if event.type == "program" or event.type == "interrupt" then
port.a = not pin.a
end
If you lack the reality, go on a trip or find a job.
Re: LUACONTROLLER UNDERSTANDING
Got it.Hume2 wrote: ↑Mon Sep 28, 2020 07:09It's because your code relies on that there are no incoming events, only program and interrupt. Turning on or off the other ports sends the luacontroller more interrupts so the code is being run more times. To avoid this, you need to check if the code was triggered by the event you expected. For example:
if event.type == "program" or event.type == "interrupt" then
port.a = not pin.a
end
Thank you Hume2 :)
Love Truth Humility
Who is online
Users browsing this forum: No registered users and 24 guests