Skip to content

Commit c77cc96

Browse files
authored
Create gemma_main.py
1 parent 5a4c1ce commit c77cc96

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

CircuitPython_TVBGone/gemma_main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Gemma M0 version of TVBgone
2+
# This will NOT work with CircuitPython 7 and later
3+
# as PulseOut is no longer available on Gemma M0
4+
# Here for educational/research purposes only
5+
6+
import array
7+
import time
8+
9+
import adafruit_dotstar
10+
import board
11+
import pulseio
12+
from digitalio import DigitalInOut, Direction
13+
14+
# pylint: disable=eval-used
15+
16+
pixel = adafruit_dotstar.DotStar(
17+
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
18+
pixel.fill((0, 0, 0))
19+
20+
# Button to see output debug
21+
led = DigitalInOut(board.D13)
22+
led.direction = Direction.OUTPUT
23+
24+
pwm = pulseio.PWMOut(board.A2, frequency=38000,
25+
duty_cycle=2 ** 15, variable_frequency=True)
26+
pulse = pulseio.PulseOut(pwm)
27+
28+
time.sleep(0.5) # Give a half second before starting
29+
30+
# gooooo!
31+
f = open("/codes.txt", "r")
32+
for line in f:
33+
code = eval(line)
34+
print(code)
35+
pwm.frequency = code['freq']
36+
led.value = True
37+
# If this is a repeating code, extract details
38+
try:
39+
repeat = code['repeat']
40+
delay = code['repeat_delay']
41+
except KeyError: # by default, repeat once only!
42+
repeat = 1
43+
delay = 0
44+
# The table holds the on/off pairs
45+
table = code['table']
46+
pulses = [] # store the pulses here
47+
# Read through each indexed element
48+
for i in code['index']:
49+
pulses += table[i] # and add to the list of pulses
50+
pulses.pop() # remove one final 'low' pulse
51+
52+
for i in range(repeat):
53+
pulse.send(array.array('H', pulses))
54+
time.sleep(delay)
55+
led.value = False
56+
time.sleep(code['delay'])
57+
58+
f.close()

0 commit comments

Comments
 (0)