I am working on a python script that involves Pygame and I am stumbling upon something... This is the code----
Code: Select all
import time
import os
import rpi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(29,GPIO.IN)
GPIO.setup(31,GPIO.IN)
GPIO.setup(32,GPIO.IN)
GPIO.setup(33,GPIO.IN)
GPIO.setup(35,GPIO.IN)
GPIO.setup(36,GPIO.IN)
GPIO.setup(37,GPIO.IN)
GPIO.setup(38,GPIO.IN)
import pygame
pygame.mixer.init(44100,-16,8,2048)
Drum1 = ('/home/pi/Drum1.wav')
Drum2 = ('/home/pi/Drum2.wav')
Drum3 = ('/home/pi/DrumSp.wav')
BassDrum = ('/home/pi/BassDrum.wav')
Cym1 = ('/home/pi/Cymbal1.wav')
Cym2 = ('/home/pi/Cymbal2.wav')
Cym3 = ('/home/pi/Cymbal3.wav')
Cym4 = ('/home/pi/Cymbal4.wav')
ch1 = pygame.mixer.Channel(0)
ch2 = pygame.mixer.Channel(1)
ch3 = pygame.mixer.Channel(2)
ch4 = pygame.mixer.Channel(3)
ch5 = pygame.mixer.Channel(4)
ch6 = pygame.mixer.Channel(5)
ch7 = pygame.mixer.Channel(6)
ch8 = pygame.mixer.Channel(7)
try:
while True:
while True:
if GPIO.input(29) ==1:
ch1.play(pygame.mixer.Sound(Drum1))
time.sleep(0.02)
break
if GPIO.input(31) ==1:
ch2.play(pygame.mixer.Sound(Drum2))
time.sleep(0.02)
break
if GPIO.input(32) ==1:
ch3.play(pygame.mixer.Sound(Drum3))
time.sleep(0.02)
break
if GPIO.input(33) ==1:
ch4.play(pygame.mixer.Sound(Cym1))
time.sleep(0.02)
break
if GPIO.input(35) ==1:
ch5.play(pygame.mixer.Sound(Cym2))
time.sleep(0.02)
break
if GPIO.input(36) ==1:
ch6.play(pygame.mixer.Sound(Cym3))
time.sleep(0.02)
break
if GPIO.input(37) ==1:
ch7.play(pygame.mixer.Sound(Cym4))
time.sleep(0.02)
break
if GPIO.input(38) ==1: ch8.play(pygame.mixer.Sound(BassDrum))
time.sleep(0.02)
break
finally:
GPIO.cleanup()
If anyone of you people can direct me on this topic, it would really be appreciated...
Thank you!
Edit: This has been solved...
I forgot to connect the Ground to the GPIO Pins.