forked from doniks/pycom-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pin.py
151 lines (130 loc) · 2.99 KB
/
pin.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# puts pin 12 high and reads pin 13
# if 13 is high, the led goes green
# 12 is bottom left, 13 is bottom right
from machine import Pin
import pycom
import time
def spin(ct, ms=100):
if ct == 0:
print('-', end='')
return
x = ct % 3
if x == 0:
print('\b\\', end='')
elif x == 1:
print('\b/', end='')
elif x == 2:
print('\b-', end='')
time.sleep_ms(ms)
def sleep(s):
for x in range(s * 10):
spin(x)
print('\b.')
def low():
print("_", end="")
out_p(0)
pycom.rgbled(0x0a000a)
time.sleep_ms(1000)
def high():
print("-", end="")
out_p(1)
pycom.rgbled(0x220022)
time.sleep_ms(1000)
def blink(pin):
for i in range(3):
pin(1)
time.sleep_ms(10)
pin(0)
time.sleep_ms(10)
def state(pin):
print(pin.id(), end=': ')
print("mode", pin.mode(), end=' ')
if pin.mode() == Pin.OUT:
print('OUT', end='')
elif pin.mode() == Pin.IN:
print('IN', end='')
elif pin.mode() == Pin.OPEN_DRAIN:
print('OD', end='')
if pin.pull() is None:
print(", pull None", end='')
elif pin.pull() == Pin.PULL_UP:
print(", pull UP", end='')
elif pin.pull() == Pin.PULL_DOWN:
print(", pull DOWN", end='')
print(", value", pin.value())
p5 = Pin('P5')
state(p5)
p8 = Pin('P8')
state(p8)
pycom.heartbeat(False)
print(dir(Pin.module))
print(dir(Pin.exp_board))
# for property, value in vars(Pin.module).items():
# print(property, ":", value)
#
# for p in dir(Pin.module):
# print(p) # , ':', Pin.module.__dict__[p])
# print(Pin.module.p)
# for p in Pin.module.__dict__:
# print(p, ':', Pin.module.__dict__[p])
# for gp in Pin.exp_board.__dict__:
# print('{:>3s}:'.format(gp), Pin.exp_board.__dict__[gp])
# out_p = Pin("P11", mode=Pin.OUT)
# out_p.value(1)
#
# in_p = Pin("P13", mode=Pin.IN, pull=Pin.PULL_UP)
# pycom.heartbeat(False)
# while True:
# if in_p():
# high()
# else:
# low()
# high()
# time.sleep_ms(100)
# print('outputs')
# # sleep(2)
# for p in range(0,23+1):
# print('Pin', p)
# if p == 0:
# print('RX0')
# continue
# elif p == 1:
# print('TX0')
# continue
# if p in [13, 14, 15, 16, 17, 18]:
# print('input only!')
# pin = Pin('P' + str(p), mode=Pin.OUT)
# # sleep(2)
# blink(pin)
def wait_low(pin):
ct = 0
while pin():
spin(ct)
ct += 1
print('\n.')
def wait_high(pin):
ct = 0
while not pin():
spin(ct)
ct += 1
print('\n.')
print('inputs')
for p in range(0,23+1):
pycom.rgbled(0x001100)
print('\nPin', p)
time.sleep(1)
pycom.rgbled(0x070700)
if p == 0:
print('RX0')
continue
elif p == 1:
print('TX0')
continue
if p = 9:
print('Expb LED')
pin = Pin('P' + str(p), mode=Pin.IN)
for i in range(3):
wait_low(pin)
print('low')
wait_high(pin)
print('high')