Page 1 of 1

Mesecons and use switch to activate Micro-controller

PostPosted: Tue Oct 18, 2016 02:58
by basil60
Hi

playing with the Mesecons mod. I have the micro-controller with lamps connected to ports B/D and switches to A/C.

I'd like the lamps to come on when a switch (A) is turned on.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
port = {a=false, b=false, c=false, d=false}
if port.a == true then
port.b = true
port.d = true
else
port.b = false
port.d = false
end

I'm not sure if there's something wrong with my code, but I sense I haven't done anything to detect the switch being activated.
I'd appreciate any advice.

Re: Mesecons and use switch to activate Micro-controller

PostPosted: Tue Oct 18, 2016 17:03
by Jeija
port is for output, pin is for input. Don't use port.a == true, use pin.a == true instead. Also see Chapter II over here: http://mesecons.net/luacontroller/

A shorter way to write your code would be:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
port.b = pin.a
port.d = pin.a