This one was long overdue, and I finally got around to doing it, and even though it’s just a damn LED light, making it glow was an extremely pleasant experience.
Following these two videos, I learnt the following.
- How to handle a solderless breadboard and how to use it to complete circuits.
- Different GPIO pins of the Raspberry pi and what they do.
- Using python to control the GPIO pin to make the LED light blink.
- Calculate the resistance I had to use using Ohm’s law.
- How to connect resistors in series on a breadboard.
Here’s a picture.
I also modified the code in the video above to make a birthday gift for a friend. I hooked up an LED light to a GPIO pin, and wrote a while loop in python to make the light blink as long as the happy birthday song was playing. Here is the code.
import RPi.GPIO as GPIO import time import pygame import sys GPIO.setmode(GPIO.BOARD) GPIO.setup(12,GPIO.OUT) pygame.mixer.init() pygame.mixer.music.load("song.mp3") pygame.mixer.music.play() while pygame.mixer.music.get_busy() == True: GPIO.output(12,GPIO.HIGH) time.sleep(1) GPIO.output(12,GPIO.LOW) time.sleep(1) while pygame.mixer.music.get_busy() == False: GPIO.cleanup() sys.exit()