Exemple #1
0
def get_talk_time(minutes):
    """Setup talk time"""
    display.scroll('A -1, B +1')

    # clear press counters

    button_a.get_presses()
    button_b.get_presses()

    quit_flag = False

    while quit_flag is not True:
        minutes = minutes - button_a.get_presses() \
            + button_b.get_presses()
        display_minutes(int(minutes))

        # To exit press a for 2 seconds

        if button_a.is_pressed():
            start = running_time()

            while button_a.is_pressed():
                if running_time() - start > 2000:
                    quit_flag = True
                    display.scroll(str(int(minutes)))

    return minutes
Exemple #2
0
def main():
    global C
    display_init()
    D.repaint(60)
    D.clear()
    press_count = A.get_presses() + B.get_presses()
    while press_count == A.get_presses() + B.get_presses():
        pulse(150)
    C = running_time()
    D.repaint(60)
    run_game()
    game_over()
Exemple #3
0
def Speed_measurement():
    pin14.write_digital(1)
    sleep(5000)
    IR_R = button_a.get_presses()
    IR_L = button_b.get_presses()
    RPM_R = IR_R
    RPM_L = IR_L
    print("\r" + "RPM_R:{:3.0f}r/min".format(RPM_R),
          "RPM_L:{:3.0f}r/min".format(RPM_L),
          end='')
Exemple #4
0
 def get_cast_spell(self):
     chain = []
     for _ in range(self.level):
         if (button_a.get_presses() > 0):
             chain.append("A")
             display.show("A")
         elif (button_b.get_presses() > 0):
             chain.append("B")
             display.show("B")
     return chain
Exemple #5
0
    value = value // abs(value)
    if value > 0:
        return positive
    return negative


radio.on()


while True:
    rv = None
    ct_a = button_a.get_presses()
    if ct_a > 0:
        rv = 'btn:a'
    else:
        ct_b = button_b.get_presses()
        if ct_b > 0:
            rv = 'btn:b'
    if rv is not None:
        print(rv)
        radio.send(rv)
        sleep(SLEEP_TIME)

    value = None
    for direction in DIRECTIONS:
        value = get_direction(*direction)
        if value is not None:
            break
    if value is None:
        display.show(Image("00000:03730:07970:03730:00000"))
    else:
    [255, 0, 255],  # purple
    [255, 80, 0]  # orange
)
color_i = 0
color = colors[color_i]
rainbow = Rainbow()
leds = range(24)

i = 0
ii = 1

while True:
    while True:
        if button_a.get_presses():
            break
        if button_b.get_presses():
            color_i += 1
            if color_i >= len(colors):
                color_i = 0
            color = colors[color_i]
    
        heartbeat(l)

        for other_led in (0, 1, 2, 3, 4, 5):
            np[l - other_led] = [max(c - int(c * 0.2 * other_led) - 1, 0) for c in color]
        np.show()
        sleep(100)
        l += 1
        if l >= 24:
            l = 0
Exemple #7
0

def memRead(progcount=pc):
    global databyte, memory
    databyte = bin00(memory[progcount])
    dataWrite(bin00(progcount), 1)
    dataWrite(databyte)


#main program loop
while True:
    level()
    sleep(200)
    if (button_a.is_pressed()):
        longpress = 0
        clicks = button_b.get_presses()
        clicks = 0
        while button_a.is_pressed():
            sleep(100)  #wait until button released
            longpress = longpress + 1
        #clicks = button_a.get_presses()
        if longpress > 5:  #optons if button down >0.5second
            clicks = button_b.get_presses()
            if clicks == 1:  #run
                run()
                memRead(pc)
            elif clicks == 2:  #load mem.dat
                #i = 0
                try:
                    with open('data.bin', 'rb') as f:
                        #split the file read in two to avoid MemoryError
Exemple #8
0
from microbit import display
from microbit import sleep
from microbit import button_a, button_b

effects = 1

while True:
    display.clear()
    effects -= button_a.get_presses()
    effects += button_b.get_presses()
    if effects > 0:
        for i in range(10):
            display.set_pixel(2, 2, i)
            sleep(10)
    if effects > 1:
        for i in range(4, 10):
            display.set_pixel(2, 1, i)
            display.set_pixel(2, 3, i)
            display.set_pixel(1, 2, i)
            display.set_pixel(3, 2, i)
            sleep(20)
    if effects > 2:
        for i in range(2, 10):
            display.set_pixel(1, 1, i)
            display.set_pixel(3, 1, i)
            display.set_pixel(1, 3, i)
            display.set_pixel(3, 3, i)
            display.set_pixel(2, 2, 9 - i)
            sleep(20)
    if effects > 3:
        for i in range(9, -1, -1):
Exemple #9
0
    def generate(self, requested=0):
        particle_count = len(self.particles)
        self.max_particles = max(requested + self.max_particles, 0)
        if self.max_particles > 0:
            new_particle_count = self.max_particles - particle_count
            for i in range(new_particle_count):
                particle = FallingParticle(
                    random.randint(MIN_SPEED, MAX_SPEED),
                    random.randint(0, MAX_X))
                self.particles.append(particle)

    def render(self):
        display.clear()
        for particle in self.particles:
            display.set_pixel(particle.x, particle.y, particle.brightness)

    def advance(self):
        for particle in self.particles[:]:
            particle.drop()
            if particle.y > MAX_Y:
                self.particles.remove(particle)


animator = Animator()
while True:
    animator.generate(requested=button_a.get_presses() -
                      button_b.get_presses())
    animator.render()
    animator.advance()
    sleep(100)