diff --git a/CircuitPython_TVBGone/gemma_main.py b/CircuitPython_TVBGone/gemma_main.py new file mode 100644 index 000000000..2031bc0d5 --- /dev/null +++ b/CircuitPython_TVBGone/gemma_main.py @@ -0,0 +1,58 @@ +# Gemma M0 version of TVBgone +# This will NOT work with CircuitPython 7 and later +# as PulseOut is no longer available on Gemma M0 +# Here for educational/research purposes only + +import array +import time + +import adafruit_dotstar +import board +import pulseio +from digitalio import DigitalInOut, Direction + +# pylint: disable=eval-used + +pixel = adafruit_dotstar.DotStar( + board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +pixel.fill((0, 0, 0)) + +# Button to see output debug +led = DigitalInOut(board.D13) +led.direction = Direction.OUTPUT + +pwm = pulseio.PWMOut(board.A2, frequency=38000, + duty_cycle=2 ** 15, variable_frequency=True) +pulse = pulseio.PulseOut(pwm) + +time.sleep(0.5) # Give a half second before starting + +# gooooo! +f = open("/codes.txt", "r") +for line in f: + code = eval(line) + print(code) + pwm.frequency = code['freq'] + led.value = True + # If this is a repeating code, extract details + try: + repeat = code['repeat'] + delay = code['repeat_delay'] + except KeyError: # by default, repeat once only! + repeat = 1 + delay = 0 + # The table holds the on/off pairs + table = code['table'] + pulses = [] # store the pulses here + # Read through each indexed element + for i in code['index']: + pulses += table[i] # and add to the list of pulses + pulses.pop() # remove one final 'low' pulse + + for i in range(repeat): + pulse.send(array.array('H', pulses)) + time.sleep(delay) + led.value = False + time.sleep(code['delay']) + +f.close()