import Adafruit_BBIO.GPIO as G
import time
l1 = "P8_12"
l2 = "P8_18"
l3 = "P8_16"
b1 = "P8_11"
b2 = "P8_13"
b3 = "P8_26"
G.setup(l1,G.OUT)
G.setup(l2,G.OUT)
G.setup(l3,G.OUT)
G.setup(b1,G.IN)
G.setup(b2,G.IN)
G.setup(b3,G.IN)
def glow(cur):
if(cur==1):
G.output(l1,G.HIGH)
G.output(l2,G.LOW)
G.output(l3,G.LOW)
elif(cur==2):
G.output(l2,G.HIGH)
G.output(l1,G.LOW)
G.output(l3,G.LOW)
elif(cur==3):
G.output(l3,G.HIGH)
G.output(l2,G.LOW)
G.output(l1,G.LOW)
time.sleep(2)
def chf(cur, next):
while(cur!=next):
if(cur>next):
cur=cur-1
else:
cur=cur+1
glow(cur)
cur=1
next=1
while True:
if(G.input(b1)==1):
next=1
chf(cur,next)
cur=next
elif(G.input(b2)==1):
next=2
chf(cur,next)
cur=next
elif(G.input(b3)==1):
next=3
chf(cur,next)
cur=next
import time
l1 = "P8_12"
l2 = "P8_18"
l3 = "P8_16"
b1 = "P8_11"
b2 = "P8_13"
b3 = "P8_26"
G.setup(l1,G.OUT)
G.setup(l2,G.OUT)
G.setup(l3,G.OUT)
G.setup(b1,G.IN)
G.setup(b2,G.IN)
G.setup(b3,G.IN)
def glow(cur):
if(cur==1):
G.output(l1,G.HIGH)
G.output(l2,G.LOW)
G.output(l3,G.LOW)
elif(cur==2):
G.output(l2,G.HIGH)
G.output(l1,G.LOW)
G.output(l3,G.LOW)
elif(cur==3):
G.output(l3,G.HIGH)
G.output(l2,G.LOW)
G.output(l1,G.LOW)
time.sleep(2)
def chf(cur, next):
while(cur!=next):
if(cur>next):
cur=cur-1
else:
cur=cur+1
glow(cur)
cur=1
next=1
while True:
if(G.input(b1)==1):
next=1
chf(cur,next)
cur=next
elif(G.input(b2)==1):
next=2
chf(cur,next)
cur=next
elif(G.input(b3)==1):
next=3
chf(cur,next)
cur=next
No comments:
Post a Comment