Getting started with electronics with the Raspberry Pi : LED Hello World.

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.

I just followed this video and also this video on YouTube. I highly recommend following that channel, because almost all of his videos have to do with the Raspberry Pi and electronics.

Following these two videos, I learnt the following.

Here’s a picture.

An LED light glowing. Note that here I used a 5v pin and not the GPIO pin. This 5v pin is connected to the main powerline of the Raspberry Pi.
An LED light glowing. Note that here I used a 5v pin and not the GPIO pin. This 5v pin is connected to the main powerline of the Raspberry Pi.

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()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s