def draw_pattern(pattern): keypad.clear() for i in range(16): if i in pattern: button = pattern[i] keypad.illuminate(i, button[0], button[1], button[2]) keypad.update()
def won(): on = 1 while True: # flash key 15 if on: keypad.illuminate(15, 0x00, 0x80, 0x00) on = 0 else: keypad.illuminate(15, 0x00, 0x00, 0x00) on = 1 keypad.update() time.sleep(1) # return when key 15 is pressed if keypad.get_button_states() == 32768: return
def scroll(): global PIXELS for j in range(1,4): for k in range(4): PIXELS[(4-j)*4+k] = max(0, PIXELS[(4-j-1)*4+k] - 75) keypad.illuminate((4-j)*4+k, 0, PIXELS[(4-j)*4+k] , 0) for i in range(4): if getrandbits(8) > 180: PIXELS[i] = random_color() keypad.illuminate(i, 0, PIXELS[i], 0) else: PIXELS[i] = 0 keypad.illuminate(i, 0, 0, 0) keypad.update()
colour_index = 0 else: button = 0 for find in range(0, NUM_PADS): # check if this button is pressed and no other buttons are pressed if button_states & 0x01 > 0: if not (button_states & (~0x01)) > 0: lit = lit | (1 << button) break button_states >>= 1 button += 1 for i in range(0, NUM_PADS): if (lit >> i) & 0x01: if colour_index == 0: keypad.illuminate(i, 0x00, 0x20, 0x00) elif colour_index == 1: keypad.illuminate(i, 0x20, 0x20, 0x00) elif colour_index == 2: keypad.illuminate(i, 0x20, 0x00, 0x00) elif colour_index == 3: keypad.illuminate(i, 0x20, 0x00, 0x20) elif colour_index == 4: keypad.illuminate(i, 0x00, 0x00, 0x20) elif colour_index == 5: keypad.illuminate(i, 0x00, 0x20, 0x20) else: keypad.illuminate(i, 0x05, 0x05, 0x05) keypad.update()
def lightUp(x): rgb = colourwheel(noteGrid[x]*16) keypad.illuminate(x, rgb[0], rgb[1], rgb[2])
chordOn(noteGrid[key]) lightUp(key) keypad.update() # Play the sequencer on our time schedule newtime_ms = time.ticks_ms() if (newtime_ms > time_ms): # Time to wake up! # Calculate the next "tick" millisecond counter from the TEMPO time_ms = newtime_ms + 60000/TEMPO # Turn off the last step unless the key has just been pressed, # in which case leave it on for one more step... if (step != lastkey): keypad.illuminate(step,0,0,0) lastkey = -1 step+=1 if (step >= NUM_PADS): step = 0 # And turn off any last notes playing for note in range (NUM_NOTES): chordOff(note) # Illuminate the new step if (noteGrid[step] == 0): keypad.illuminate(step, 2,2,2) else: lightUp(step)
shuffle(answer) if debug: print(answer) lit = 0 button_states = keypad.get_button_states() if last_button_states != button_states: last_button_states = button_states if button_states > 0: button = -1 for i in range(0, NUM_PADS): if button_states == 2**i: button = i break #print(lit,button_states,button) if answer[lit] == button: keypad.illuminate(button, 0x00, 0x20, 0x00) keypad.update() lit += 1 else: for i in range(0, NUM_PADS): x = (i + button) % NUM_PADS keypad.illuminate(x, 0x20, 0x00, 0x00) keypad.update() time.sleep(0.05) time.sleep(0.2) for i in range(0, NUM_PADS): keypad.illuminate(i, 0x00, 0x00, 0x00) keypad.update() lit = 0 if lit == maxlength: time.sleep(1)
import time import picokeypad as keypad keypad.init() keypad.set_brightness(0.75) NUM_PADS = keypad.get_num_pads() i = 0 colour_index = 0 while True: if colour_index == 0: keypad.illuminate(i, 0, 255, 0) elif colour_index == 1: keypad.illuminate(i, 255, 255, 0x00) elif colour_index == 2: keypad.illuminate(i, 255, 0x00, 0x00) elif colour_index == 3: keypad.illuminate(i, 255, 0x00, 255) elif colour_index == 4: keypad.illuminate(i, 0x00, 0x00, 255) elif colour_index == 5: keypad.illuminate(i, 0x00, 255, 255) keypad.update() i += 1 if i > 15: i = 0 colour_index += 1 if colour_index > 5:
def clear_display(): global PIXELS for pixel_index in range(16): PIXELS[pixel_index] = 0 keypad.illuminate(pixel_index, 0, 0, 0) keypad.update()