-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (85 loc) · 2.46 KB
/
main.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from time import sleep_ms
from machine import Pin, SPI, SoftI2C, UART, ADC
import gc
from drivers.ssd1306.ssd1306 import SSD1306_I2C as SSD
import framebuf
pLED = Pin(2, Pin.OUT)
pTasterA = Pin(5,Pin.IN, Pin.PULL_UP)
pTasterB = Pin(18,Pin.IN, Pin.PULL_UP)
pTasterC = Pin(19,Pin.IN, Pin.PULL_UP)
adcPotiD = ADC(4)
adcPotiE = ADC(15)
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
gc.collect()
ssd = SSD(128, 64, i2c)
alpaca = framebuf.FrameBuffer(bytearray(11 * 11 * 2), 11, 11, framebuf.MONO_HLSB)
alpaca.hline(1, 0, 2, 1)
alpaca.hline(8, 0, 2, 1)
alpaca.rect(0, 1, 4, 3, 1, True)
alpaca.rect(7, 1, 4, 3, 1, True)
alpaca.rect(4, 2, 4, 2, 1, True)
alpaca.vline(0, 4, 5, 1)
alpaca.vline(10, 4, 5, 1)
alpaca.pixel(1, 4, 1)
alpaca.pixel(9, 4, 1)
alpaca.vline(1, 8, 2, 1)
alpaca.vline(2, 9, 2, 1)
alpaca.vline(9, 8, 2, 1)
alpaca.vline(8, 9, 2, 1)
alpaca.hline(3, 10, 5, 1)
alpaca.pixel(2, 6, 1)
alpaca.pixel(8, 6, 1)
alpaca.pixel(4, 7, 1)
alpaca.pixel(6, 7, 1)
alpaca.hline(4, 8, 3, 1)
ssd.blit(alpaca, 59, 27)
ssd.show()
uart = UART(2,baudrate=115200) # 16:RX 17:TX
class Taster:
def __init__(self, pin, text):
self.pin = pin
self.text = text
self.was_sent = False
def send(self):
if self.pin.value() == 0 and self.was_sent == False:
self.was_sent = True
uart.write(self.text)
print(self.text + " sent")
if self.pin.value() == 1:
self.was_sent = False
class Potenziometer:
def __init__(self, adc, text):
self.adc = adc
self.text = text
self.last_value = 0
def send(self):
value = self.adc.read()
if value != self.last_value:
self.last_value = value
uart.write(self.text + str(value))
print(self.text + " sent ", value)
def serialecho():
print("serial hello started")
tasterA = Taster(pTasterA,"A")
tasterB= Taster(pTasterB,"B")
tasterC = Taster(pTasterC,"C")
potiD = Potenziometer(adcPotiD, "D")
potiE = Potenziometer(adcPotiE, "E")
while True:
tasterA.send()
tasterB.send()
tasterC.send()
# potiD.send()
# potiE.send()
# sleep_ms(2000)
pLED.value(uart.any())
while uart.any():
x=uart.read().decode("utf-8")
print("Got", x)
ssd.fill(0)
ssd.text(x,15,5)
ssd.blit(alpaca, 59, 27)
ssd.show()
# uart.write(x)
sleep_ms(100)
serialecho()