Mesecons and use switch to activate Micro-controller

Post Reply
basil60
Member
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Mesecons and use switch to activate Micro-controller

by basil60 » Post

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.

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.

User avatar
Jeija
Member
Posts: 686
Joined: Fri Dec 23, 2011 21:46
Location: Nürtingen, Germany

Re: Mesecons and use switch to activate Micro-controller

by Jeija » Post

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:

Code: Select all

port.b = pin.a
port.d = pin.a

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 23 guests