File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ try :
2+ import umachine as machine
3+ except ImportError :
4+ import machine
5+ try :
6+ machine .PinBase
7+ machine .time_pulse_us
8+ except AttributeError :
9+ print ("SKIP" )
10+ import sys
11+ sys .exit ()
12+
13+
14+ class ConstPin (machine .PinBase ):
15+
16+ def __init__ (self , value ):
17+ self .v = value
18+
19+ def value (self , v = None ):
20+ if v is None :
21+ return self .v
22+ else :
23+ self .v = v
24+
25+
26+ class TogglePin (machine .PinBase ):
27+
28+ def __init__ (self ):
29+ self .v = 0
30+
31+ def value (self , v = None ):
32+ if v is None :
33+ self .v = 1 - self .v
34+ print ("value:" , self .v )
35+ return self .v
36+
37+
38+ p = TogglePin ()
39+
40+ t = machine .time_pulse_us (p , 1 )
41+ print (type (t ))
42+ t = machine .time_pulse_us (p , 0 )
43+ print (type (t ))
44+
45+ p = ConstPin (0 )
46+ try :
47+ machine .time_pulse_us (p , 1 , 10 )
48+ except OSError :
49+ print ("OSError" )
50+
51+ try :
52+ machine .time_pulse_us (p , 0 , 10 )
53+ except OSError :
54+ print ("OSError" )
Original file line number Diff line number Diff line change 1+ value: 1
2+ value: 0
3+ <class 'int'>
4+ value: 1
5+ value: 0
6+ value: 1
7+ <class 'int'>
8+ OSError
9+ OSError
You can’t perform that action at this time.
0 commit comments