def main(): player_1 = chessclock.ChessClock(time_left = 60, display = segments.Seg7x4(i2c), pin = DigitalInOut(board.D6), increment=5) player_2 = chessclock.ChessClock(time_left = 60, display = segments.Seg7x4(i2c, address=0x71), pin = DigitalInOut(board.D5), increment=5) while player_1.active == False and player_2.active == False: #Game starts when a player presses thier timer, opposite clock starts. player_1.switch.update() if player_1.switch.fell: player_2.active = True player_2.switch.update() if player_2.switch.fell: player_1.active = True while True: #Run this loop during player_1's turn. while player_1.active and (player_1.flagged == False): if player_1.started == False: player_1.start() player_1.run_clock() else: player_1.resume() player_1.run_clock() if player_1.switch.fell: #Check if player_1 ends their turn. player_1.active = False player_2.active = True #Run this loop during player_2's turn. while player_2.active and (player_2.flagged == False): if player_2.started == False: player_2.start() player_2.run_clock() else: player_2.resume() player_2.run_clock() if player_2.switch.fell: #Check if player_2 ends their turn. player_2.active = False player_1.active = True
def clear_display(): # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # Create the LED segment class. # This creates a 7 segment 4 character display: display = segments.Seg7x4(i2c) # Clear the display. display.fill(0)
def clock_handler(address, *args): print(f"{address}: {args}") import time import datetime from adafruit_ht16k33 import segments import busio import board # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # Create the LED segment class. # This creates a 7 segment 4 character display: display = segments.Seg7x4(i2c) # clear display display.fill(0)
def setup_display(): # please check that POSOTIONS has been changed in # /usr/local/lib/python3.5/dist-packages/adafruit_ht16k33/segments.py # to be like # POSITIONS = (0, 2, 4, 6) # The positions of characters. # global display # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # Create the LED segment class. # This creates a 7 segment 4 character display: display = segments.Seg7x4(i2c) # Clear the display. display.fill(0) return
import time import board import busio from adafruit_ht16k33 import segments # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # Create the LED segment class. # This creates a 7 segment 4 character display: display = segments.Seg7x4(i2c) # Clear the display. display.fill(0) # Can just print a number display.print(42) time.sleep(1) # Set the first character to '1': display[0] = '1' # Set the second character to '2': display[1] = '2' # Set the third character to 'A': display[2] = 'A' # Set the forth character to 'B': display[3] = 'B' time.sleep(1) numbers = [0.0, 1.0, -1.0, 0.55, -0.55, 10.23, -10.2, 100.5, -100.5]
import time # Import all board pins. import board import busio # Import the HT16K33 LED segment module. from adafruit_ht16k33 import segments # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) # Create the LED segment class. # This creates a 7 segment 4 character display: display = segments.Seg7x4(i2c, address=(0x70, 0x71)) # Or this creates a 14 segment alphanumeric 4 character display: # display = segments.Seg14x4(i2c, address=(0x70, 0x71)) # Clear the display. display.fill(0) # Can just print a number display.print(12345678) time.sleep(2) # Or, can print a hexadecimal value display.fill(0) display.print_hex(0xFF23) time.sleep(2)
def __init__(self, address=0x70, i2c=None): super().__init__() if i2c is None: i2c = board.I2C() self._segments = segments.Seg7x4(i2c, address) self._segments.auto_write = False
# Create the character dictionary # You can use the list normally referenced as a starting point custom_chars = {} typical_list_values = segments.NUMBERS typical_list_chars = list("0123456789abcdef-") for char, value in zip(typical_list_chars, typical_list_values): custom_chars[char] = value # Add the custom characters you want custom_chars["s"] = 0b01101101 custom_chars["r"] = 0b01010000 custom_chars["o"] = 0b00111111 custom_chars["l"] = 0b00110000 custom_chars["i"] = 0b00010000 custom_chars["n"] = 0b01010100 custom_chars["g"] = 0b01101111 # Create the I2C interface. i2c = busio.I2C(board.SCL, board.SDA) display = segments.Seg7x4(i2c, char_dict=custom_chars) # Clear the display. display.fill(0) # Now you can print custom text display.print("cool") time.sleep(3) # You can also marquee custom text display.marquee("scrolling... ", 0.2)
def __init__(self, i2c): self.i2c = i2c self.display = segments.Seg7x4(i2c) self.mode = AF_HT16K33_7Seg.MODE_MMSS self.blink = False Logger.instance.log("Loaded I2C 7-segment display.")
def display_initialize(i2c): display = segments.Seg7x4(i2c) display.fill(0) return display