How to Read a Switch
.jpeg)
So far we've covered how to blink an LED on and off and how to flicker an LED using an analogue output value, it's time to start reading and reacting to inputs to the controller. This means adding some additional hardware to read from, but today that can be a simple as a single wire on a prototyping breadboard. One end of the wire is connected to the D1 input and the other end is swapped between the 3V3 pin and the GND pin to create High/Low input signals. The initial code to read this is impressively simple, we're also going to leave some LED code in the demo so that we can easily see what value is being read by the controller. When you load this example you should see that the LED turns on when the wire is connected to GND (remember the LED_BUILTIN is active low) and the LED turns off when the wire is connected to 3V3. This system works but has a downside, the input pin only changes state when the wire is connected to the new pin. When the wire is disconnected and l...