示例#1
0
 def miss(self):
     clear(self.field_pins)
     for i in range(4): ### blink the whole field
         light(self.field_pins)
         sleep(0.2)
         clear(self.field_pins)
         sleep(0.2)
示例#2
0
 def __init__(self, LL, UL, LR, UR):
     self.field = [[LL, UL], [LR, UR]]
     self.field_pins = [LL, UL, LR, UR]
     self.x = random.randint(0,1)
     self.y = random.randint(0,1)
     clear(self.field_pins)
     light(self.field[self.x][self.y])
示例#3
0
 def __init__(self, low, high):
     self.range = [low, high]
     self.y = random.randint(0,1)
     clear(self.range)
     for i in range(6):
         light(self.range[self.y])
         sleep(0.1)
         clear(self.range)
         sleep(0.1)
     light(self.range[self.y])
示例#4
0
def aabb(x, t):
    assert type(x) == int
    assert 0 <= x <= xmax
    k = 0.7 # Defines how legato vs staccato
    for i in range(2):
        for j in range(2):
            encode(x, pins)
            sleep(t * k)
            clear(pins)
            sleep(t * (1-k))
        for j in range(2):
            encode(xmax - x, pins)
            sleep(t * k)
            clear(pins)
            sleep(t * (1-k))
示例#5
0
 def move(self, direction):
     assert (direction==0 or direction==1)
     self.y = direction
     clear(self.range)
     light(self.range[self.y])
示例#6
0
 def hit(self):
     self.x = self.x ^ 1 # always go to opposite side
     self.y = random.randint(0,1)
     clear(self.field_pins)
     light(self.field[self.x][self.y])
     sleep(1)
示例#7
0
p1 .  .  .
"""

from blinkenlights import setup, cleanup
from fourleds import light, clear
from time import sleep
import random

pins = [37, 33, 31, 29, 36, 32, 22, 18]
#       yp  ym  gp  gm  rp  rm  bp  bm

setup(pins)

### Test pattern

clear(pins)
for i in pins:
    light(i)
    sleep(0.1)
    clear(pins)

#### Definitions

class Ball:
    def __init__(self, LL, UL, LR, UR):
        self.field = [[LL, UL], [LR, UR]]
        self.field_pins = [LL, UL, LR, UR]
        self.x = random.randint(0,1)
        self.y = random.randint(0,1)
        clear(self.field_pins)
        light(self.field[self.x][self.y])