-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.py
More file actions
executable file
·56 lines (48 loc) · 2.07 KB
/
code.py
File metadata and controls
executable file
·56 lines (48 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from board import A3, A2, A1, A0, SCK, MISO, MOSI, D10, D5, D6, D3, D1
from digitalio import DigitalInOut, Direction, Pull
from adafruit_debouncer import Button
from typey import TypeManager
# user switch as Debounced Button
button = DigitalInOut(D1)
button.switch_to_input(pull=Pull.UP)
switch = Button(button, long_duration_ms=600)
# BUSY high informs host that printer is busy and should wait before next data
BUSY = DigitalInOut(D6)
BUSY.direction = Direction.INPUT
BUSY.pull = Pull.DOWN
# SEL To Host - A high value indicates that a printer is present
SEL = DigitalInOut(D3)
SEL.direction = Direction.INPUT
SEL.pull = Pull.DOWN
# STROBE - To Printer, low pulse indicates that there’s valid data on D[7:0]
STROBE = DigitalInOut(D5)
STROBE.direction = Direction.OUTPUT
STROBE.value = 1
# high/low values on these pins indicate the binary data being sent
# DB25 pin num: p2 p3 p4 p5 p6 p7 p8 p9
board_pin_list = [D10, MOSI, MISO, SCK, A0, A1, A2, A3]
# binary data bit: 7 6 5 4 3 2 1 0
# list is organized bit 7:0 so that short binary chars like '01010' slot easily
# into the for loop in sendChar()
# initialize pins as digitalio objects
for num, pin in enumerate(board_pin_list.copy()):
board_pin_list[num] = DigitalInOut(pin)
board_pin_list[num].direction = Direction.OUTPUT
board_pin_list[num].value = 0
typeWriter = TypeManager(board_pin_list, BUSY, SEL, STROBE, switch)
story = "not a story...yet!\n\n\n"
folder = "/stories/"
while True:
# update switch and check for a button press, and if printer is present
switch.update()
if SEL.value and switch.fell:
try:
with open(folder+'2_MERCEDES.txt', 'r') as reader:
# the entire text file is dumped into a string
story = reader.read()
typeWriter.sendText(story)
# in the sendText loop sendChar() is used to send data char by char
# long press the switch will break out of the loop
except OSError:
typeWriter.sendText("no file found\n\n\n\n")
print("file not found, try again?")