morse_engine.py 1.48 KB
import time
from src import morse_code

# Constants (Keep same or tests will break)
THRESHOLD = 75
UNIT_TIME = 0.24

RED = (255, 0, 0)
YELLOW = (220, 160, 0)
GREEN = (0, 255, 0)

# Legacy ham radio license requirement
# - 0.24 sec unit time (5 words per minute)
# Fastest recorded transcription on a straight key
# - 0.034 sec unit time (35 words per minute)


def set_color(elapsed_t, px):
    """Lights the LEDs on the trinkey depending on length of input.
    The LED should be lit red (255, 0, 0) if the input is shorter than UNIT_TIME.
    The LED should be lit yellow (220, 160, 0) if the input is between 1 and 3 times UNIT_TIME.
    The LED should be lit green (0, 255, 0) if the input is longer than 3 times UNIT_TIME.
    """
    pass


def add_mark(elapsed_t):
    """Determines if input is a dot (.) or dash (-) depending on length of input.
    Returns an empty string if the input is less than UNIT_TIME.
    Returns a dot if the input is between 1 and 3 times UNIT_TIME.
    Returns a dash if the input is greater than 3 times UNIT_TIME.
    """
    pass


def run_morse_engine(apds, pixels, touch):
    """A Tests Demo on Trinkey"""
    down = None  # Time when proximity sensor was first triggered
    elapsed = 0  # Duration proximity sensor has been triggered
    message = ""  # Translated part of message
    letter = ""  # Dots and dashes of current (unfinished) letter

    # Main loop
    while True:
        if touch.value:
            print("Touched!")

        print(message, letter, "<==")