3 ms·
A relay is an electrically controlled switch. If the coil (c) is powered then the switch state goes from its default state to the alternate. So a default on swi
by Jtsummers 2y ago
A relay is an electrically controlled switch. If the coil (c) is powered then the switch state goes from its default state to the alternate. So a default on switch passes on the value of in to its output if c = 0, but when c = 1 (the coil is powered) the switch is opened, or toggled off. For a default off switch it is the reverse.
c = coil, if it is powered it will toggle the switch.
in = the value (1 or 0 here) that will pass through if the switch is closed.
In code:
def default_on(c, in):
if c == 1: return 0
if c == 0: return in
def default_off(c, in):
if c == 1: return in
if c == 0: return 0
The separate power source allows you to obtain a 1 value (since this is around digital logic I'm not going to break it down further) regardless of what the two input values are.
Consider a situation like this: How would you output 1 every time both inputs are 0? You need some high value to draw from, that's what the power source is for. So the input signals themselves may not be enough.
- theogravity 2y agoThank you.
- Eisenstein 2y agoFYI the creator of the game responds to emails. I got stuck and didn't understand something and wrote a quick email and got an explanation.
- Jtsummers 2y agoThe book Code by Petzold talks about computers at this low level (relays) and works up to a small processor. It's pop tech, very readable, second edition came out a couple years back. If you're interested in how these relays would work for something like this, he goes into it. https://codehiddenlanguage.com https://codehiddenlanguage.com https://codehiddenlanguage.com/Chapter08/ https://codehiddenlanguage.com/Chapter08/ - illustrates logic with relays.
- devilbunny 2y agoI'm a doctor, not a coder or IT guy. I've always found computers fascinating. And Code was the first time I understood how they worked. It's a brilliant book.