Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import RPi.GPIO as GPIO
- import sys
- import math
- pins = [7, 11, 13, 15, 16, 18, 22, 29, 31, 32, 33, 35, 36, 37, 38, 40] #Available Pins
- bits=0 #This will be the amount of LEDs
- pinsalias=[] #I will rename every Pin so that parameter getting easier
- pinsalias.append(0)
- ####DEFINE###############
- def setup_gpioo (int1): #Setup Every Pin i am going to need and check for available pins
- i=0
- global bits
- global pinsalias
- for x in range(len(pins)):
- if (int1 == pins[x]) : i=1
- if (i == 1) :
- pinsalias.append(int1)
- GPIO.setup(int1, GPIO.OUT)
- else:
- print str(int1) + " no available pin!"
- GPIO.cleanup()
- sys.exit()
- bits=len(pinsalias)-1
- return;
- def set_o (int1,bool2,sleep3): #not really needed but..
- GPIO.output(pinsalias[int1],bool2)
- if (sleep3 != 0) : time.sleep(sleep3)
- return;
- def reset_o(): #set every OUTPUT to 0, i know there is GPIO.cleanup() but its kinda buggy
- for xcount in range(bits):
- set_o (xcount+1,0,0)
- return;
- def DecToBinO (evt1,dur1,int1): #Calculator + Output in Binary
- check=0
- dcount=0
- while check==0: #Do until Check = 1
- if (evt1==0): #If paramter evt1(WaitforEvent) == 0 then its just a for loop
- dcount=dcount+1
- if (dcount==int1):check=1
- elif (evt1==1): #If paramter evt1(WaitforEvent) == 1 then wait for input / i am going to place some buttons on my breadbord with this event
- if (raw_input()=="q"):check=1
- dcount=dcount+1
- ccount=dcount
- if (ccount > (math.pow(2,bits)-1)): #Check for maximum available number for my LED Bits
- dcount = 0
- print "No more available Bits - Reset to 0"
- else:
- str1=""
- a=0
- c=bits-1
- while ccount!=0: #Convert Dec to Bin
- str1 = ("0" if ccount%2==0 else "1")+str1
- ccount/=2
- while len(str1)!=bits:
- str1="0"+str1 #Fill up the empty spaces with 0's
- print str1
- reset_o()
- while a!=bits: #Activate the Leds in the certain pattern
- set_o (a+1,int(str1[c]),0)
- c=c-1
- a=a+1
- if (evt1==0):time.sleep(dur1)
- return;
- def pat_o (pat1,dur1,pause1): #Another Function with Patterns for the LED. Until now only one Algorithm...
- if (pat1 == 1): ####WAVE_PATTERN
- reset_o()
- for a in range(dur1):
- reset_o()
- for aa in range(1,bits+1):
- if (aa==1):
- set_o(aa,1,pause1)
- else:
- set_o(aa-1,0,0)
- set_o(aa ,1,pause1)
- else:
- print str(pat1) +" is no available pattern"
- reset_o()
- return;
- #Setup the Pins and Board mode
- GPIO.setmode(GPIO.BOARD)
- setup_gpioo (7)
- setup_gpioo (11)
- setup_gpioo (13)
- setup_gpioo (15)
- setup_gpioo (16)
- setup_gpioo (18)
- setup_gpioo (22)
- setup_gpioo (29)
- ####MAIN#################
- reset_o()
- try:
- while True:
- pat_o(1,4,.1) #Parameter: 1 Pattern1, 4 4 times loop, .1 sleep timer
- DecToBinO(0,.2,10) #Parameter 0 For Loop, .2 Sleep between different patterns, 10 times loop
- DecToBinO(1,0,0) #Parameter 1 Wait for Event, Doesnt Matter, same
- except KeyboardInterrupt:
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement