New project!

Right! Time for a new project. This time, children, I have decided to finally do something with my raspberry pi, and I’m delighted to announce that I’ve just cobbled together my first proper bit of Python that allows me to play different sounds by pressing keys on the keyboard. Here ’tis:

import os
import pygame
pygame.init()
screen = pygame.display.set_mode((100, 100))

while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == 97:
os.system(‘mpg321 hang.mp3 &’)
if event.type == pygame.KEYDOWN and event.key == 115:
os.system(‘mpg321 keyser.mp3 &’)
if event.type == pygame.KEYDOWN and event.key == 100:
os.system(‘mpg321 lifter.mp3 &’)

This borrow heavily from this excellent Adafruit tutorial:

http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/overview

More soon!

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