Subj : Re: Python
To : Nightfox
From : Mortifis
Date : Mon Dec 10 2018 12:16 pm
> Re: Python
> By: Mortifis to All on Sun Dec 09 2018 01:40 pm
> Mo> Anyone into Python? I have a few questions relating to nested loops
> I've done a bit of Python for work.
I appreciate you looking in this for me, I think I figured out the correct loop
usage I need, python is soooo F$%&'n finicky -;P:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import random
import mutagen.mp3
import sys
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# init list with pin numbers
seq0 = [2, 3, 4, 17, 27, 22, 10, 9] # RPI GPIO PINS
seq1 = [3, 17, 22, 9]
seq2 = [2, 4, 27, 10]
seq3 = [2, 9, 3, 10, 4, 22, 17, 27, 27, 17, 22, 4, 10, 3, 9, 2]
from random import randint
rand = random.randint(0, 3)
mP3 = sys.argv[1]
from mutagen.mp3 import MP3
audio = MP3(mP3)
cycle = int(audio.info.length)
print ' Playing ', mP3, ' for ', cycle, 'seconds'
if mP3 == "letitgo.mp3":
rand = 1 # speeds timing up
SleepTimeS = 0.2
SleepTimeL = 0.1
else:
SleepTimeS = 1.2 # normal speed
SleepTimeL = 0.2
if rand == 0: seq = seq0
if rand == 1: seq = seq1
if rand == 2: seq = seq2
if rand == 3: seq = seq3
x = 0
while x < cycle:
x = x + 1
for i in seq:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
# main loop
try:
while True and x < cycle:
for i in seq:
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTimeS);
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTimeS);
GPIO.output(i, GPIO.LOW)
time.sleep(SleepTimeS);
GPIO.output(i, GPIO.HIGH)
time.sleep(SleepTimeL);
# 4 seconds to cycle loop
x = int(x + ((SleepTimeS + SleepTimeL) * 3))
except KeyboardInterrupt:
print " Quit"
GPIO.cleanup()
---
� Synchronet � The Empty Keg BBS emptykeg.synchro.net:82 Lake Echo NS Canada