Turning an LED on and off using software is an important exercise, but it’s certainly not a very useful project. Usually, you won’t control LEDs manually, but you’ll use them as status indicators. For example, many USB devices use LEDs to show whether they’re reading or writing data at the moment.
In this section, we’ll use three LEDs as status indicators for the Pi’s current memory usage. The LEDs will have the same colors as a traffic light. If the Pi’s memory is critically low, we’ll turn on the red light. If a lot of memory is available, we’ll turn on the green light. Otherwise, it will be yellow.