[Logo for The C Shore Landing Page]
The C Shore

Additional Information: Module 1, Part VI

Table of Contents

About the import statement

The line from gpiozero import LED tells Python to pull in code from the gpio library, which is code that has been written by someone else and packaged so that you can use it easily.

In this case we are importing the LED class from that library. A class is a combination of variables (assigned values) and methods (things you can do with objects created from the class). An class is abstract which means that it doesn't do anything until you give it's variables some value. When we do that we say we ‘instantiate’ (create an instance/example of) the class to create an object which is can actually ‘do’ things.

When we say led = LED(17) we are saying create an instance (object) of the LED class that has a value of 17. For the LED class that means that GPIO 17 is what the methods will act.

The led.on() applies the method on() to the object led (which in this case is means turn GPIO 17 on).

When we turn GPIO 17 on, it becomes a 3.3V power source and creates a circuit though the LED and resistor to ground.