Computers N' Stuff
Introduction
This will be a general-purpose resource which should give you a basic overview of how computers and other "smart" devices operate on a low level.
This might seem counter-intuitive at first, but in order to get a firm understanding of code and other higher-level principles such as memory management or even compiling, we need to go over the basics.
But to do that, we not only have to start in a whole different domain but also on a different scale.
The atom
Now, the atom isn't the smallest - and even though there are principles of physics that apply at an even smaller "sub-atomic" scale - this should be good enough for us.
An atom is composed of a core (which contains protons and neutrons) and an electron shell. The interesting part is that the electrons are free to move and even leave the electron shell.
FIXME: Diagram or something
Usually, each atom is in a "neutral" state - meaning it has an equal amount of protons and electrons. It is also possible for an atom to gain or lose electrons - which is what defines the charge of the atom. Atoms with less protons than electrons are "positively charged" while atoms with more protons than electrons are "negatively charged".
If an atom loses an electron, it means that either some other atom received it or the electron was released as a free floating electron (meaning it is no longer bound to an atom and can move freely in space). Likewise, if an atom gains an electron, some other atom must have lost it. The point is, atoms and electrons can't just spontaneously appear or disappear, they must have come from somewhere.
FIXME: Diagram or something
Now, if we have two atoms with different charges, some electrons will want to migrate between them until they equalize at which point both atoms become neutral, thus having the same charge in respect to each other.
For example, if we have two atoms - one of which has fewer electrons and the other has more - the electrons from the negative atom would migrate over to the positive atom until both have the same electron count.
This might again seem counter-intuitive - "but current flows from positive to negative!" - yes it indeed does, and should not be confused - the actual electron flow is always in the opposite direction of the current flow.
This means that in circuit diagrams - where current indeed flows from positive to negative - the electrons flow in the opposite direction, from negative to positive.
Now, let's not get ahead of ourselves and do a quick recap.
FIXME: Diagram or something
Electricity
Electricity, by definition, is the flow of electrons from an area with lots of negatively-charged atoms - to an area with lots of positively-charged atoms.
Certain chemical reactions are able to cause electron migration and thus create such areas of negatively-charged atoms (called "anode") and positively-charged atoms ("cathode", respectively).
If you were to connect these oppositely-charged areas with let's say, a wire, electrons would start to flow - causing what we know as "electric current".
Since wires can be made from different materials (as long as the material is conductive), it is important to understand the effect of conductivity (or resistance).
Electricity always prefers the path of lowest resistance, meaning if you have two wires, one highly conductive and one less conductive, the electrons will flow through the highly conductive one.
A "conductive" material ("conductor") has low resistance, allowing electrons to flow very easily.
A "resistive" material ("insulator") has high resistance, thus doing the opposite - hindering the flow of electrons.
However, along these two material types, there exists another: a semiconductor.
Semiconductors
Semiconductors are made out of silicon and can alter their resistance quite easily under some special conditions. For example, under certain conditions they can act as a conductor and under other conditions they can act as an insulator.
These conditions can be anything from change in pressure, light or small control voltages applied through them, depending on the type of semiconductor.
This is where all the magic happens, since this allows for all sorts of interesting behavior.
Some common "circuits" you can make with semiconductors are Switches/Flip-Flops.
They act like your regular light switches. A switch can be placed between two pieces of wire to cut off and/or restore electricity flow.
Transistors operate on the same base principle and are the best example for semiconductor devices, except that instead of physically connecting/disconnecting wires, they control the electric flow by changing their internal resistance depending on whether there is a small control voltage applied to their base.
That means that if you apply a very small voltage across the base, it can allow for the flow of a much higher voltage. This also allows them to work as amplifiers - where a small change in the "control" voltage causes a big change in the output voltage.
FIXME: NPN transistor example
FIXME: Transistor diagrams and behavior
FIXME: FINISH, all basic types, switches, t-flip/flops, other logic gates etc light switch analogy maybe, they key to it is "dumber but faster"