Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have zero experience with this, and I wish it explained what these components do. What does a relay do, what is the "c" and "in"? Why is there a separate power source, but if you hook up a / b to it and flip it on, it gets power without it?


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.


Thank you.


The 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/Chapter08/ - illustrates logic with relays.


I'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.


FYI 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.


C for coil or control. Not sure.

A relay is a mechanical switch controlled by an electromagnet composed of a coil of wire wrapped around an iron core, as depicted on the icon. When current flows through the coil, it pulls the metal spring towards it, which can either allow current to flow from "in" to the output or disconnect the current flow from "in" to the output. Those are the two types of relay components on offer.


That definitely helps, thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: