Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding other versions.

  • Loading branch information...
commit 1d21b0f042a359ecc81beebf277f151524a50b20 1 parent d8dc3da
@mrichardson23 authored
Showing with 73 additions and 1 deletion.
  1. +1 −1  aplay-sampler.py
  2. +36 −0 pygame-sampler2.py
  3. +36 −0 sampler3.py
View
2  aplay-sampler.py
@@ -8,7 +8,7 @@
GPIO.setup(8, GPIO.IN)
GPIO.setup(9, GPIO.IN)
-print "Sampler Ready."
+print("Sampler Ready.")
while True:
try:
View
36 pygame-sampler2.py
@@ -0,0 +1,36 @@
+import pygame.mixer
+from time import *
+import RPi.GPIO as GPIO
+import sys
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setup(7, GPIO.IN)
+GPIO.setup(8, GPIO.IN)
+GPIO.setup(9, GPIO.IN)
+
+pygame.mixer.init(48000, -16, 1, 1024)
+pygame.init()
+
+soundA = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Center.wav")
+soundB = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Left.wav")
+soundC = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Right.wav")
+
+soundChannel = pygame.mixer.Channel(1)
+
+print "Sampler Ready."
+while True:
+ try:
+ if (GPIO.input(7) == True):
+ soundChannel.play(soundA)
+ sleep(soundA.get_length())
+ if (GPIO.input(8) == True):
+ soundB.play()
+ sleep(soundB.get_length())
+ soundB.stop()
+ if (GPIO.input(9) == True):
+ soundC.play()
+ sleep(soundC.get_length())
+ soundC.stop()
+ sleep(.01)
+ except KeyboardInterrupt:
+ sys.exit()
View
36 sampler3.py
@@ -0,0 +1,36 @@
+import pygame.mixer
+from time import *
+import RPi.GPIO as GPIO
+import sys
+
+GPIO.setmode(GPIO.BCM)
+GPIO.setup(7, GPIO.IN)
+GPIO.setup(8, GPIO.IN)
+GPIO.setup(9, GPIO.IN)
+
+pygame.mixer.init(48000, -16, 1, 15000)
+pygame.init()
+
+soundA = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Center.wav")
+soundB = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Left.wav")
+soundC = pygame.mixer.Sound("/usr/share/sounds/alsa/Front_Right.wav")
+
+print("Sampler Ready")
+
+while True:
+ try:
+ if (GPIO.input(7) == True):
+ soundA.play()
+ sleep(soundA.get_length())
+ soundA.stop()
+ if (GPIO.input(8) == True):
+ soundB.play()
+ sleep(soundB.get_length())
+ soundB.stop()
+ if (GPIO.input(9) == True):
+ soundC.play()
+ sleep(soundC.get_length())
+ soundC.stop()
+ sleep(.01)
+ except KeyboardInterrupt:
+ sys.exit()
Please sign in to comment.
Something went wrong with that request. Please try again.