# The Lenth of time each solenoid should be activated
active_duration = 0.01
############################################# The main script#############################################
# Sets pin number to BCM mode
GPIO.setmode(GPIO.BCM)
# Calculate the time period between the solenoid being deactivated and the next beat starting
beat_gap = (float(60) / float(bpm)) - float(active_duration)
# Generator to infinitely loop around the sequence
def infinite_generator(n):
i = 0
while True:
if i >= len(n):
i = 0
yield n[ i]
i = i + 1
# Loop through each pin and set the mode and state to 'low'
for i in gpio_map:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# Run the infinite loop
try:
for beat in infinite_generator(sequence):
# Get active drum numbers
active = np.where(beat)[0]
# Get pin numbers for active drums
pins = [gpio_map[ i] for i in active]