Práctica inicial:
LED

Circuito con LED

Breadboard / Protoboard

Circuito en la protoboard

Alimentando con la RPi

Añadimos un interruptor

Controlamos el LED con Python

usando la entrada/salida GPIO número 17 de 3.3 V de la RaspberryPi

código python


#!/usr/bin/env python3

from gpiozero import LED

miled = LED(17) # crear un LED
miled.on()      # encenderlo


input("Pulsa una tecla para terminar ...")
				

Leemos el pulsador desde Python

usando la entrada/salida GPIO-02 de la RaspberryPi, y encendemos el LED

código python


#!/usr/bin/env python3

from gpiozero import LED, Button

miled = LED(17)      # crear un LED
miboton = Button(2)  # crear un pulsador

while True:
	if miboton.is_pressed:
		miled.on()
	else:
		miled.off()
				

¿Qué hemos aprendido?

  • Electricidad básica
  • Prototipado
  • GPIO de la Raspberry-Pi
  • Python - gpiozero


⇒ Volver al índice