File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
adafruit_circuitplayground Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -56,11 +56,6 @@ class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
56
56
_audio_out = None
57
57
58
58
def __init__ (self ):
59
- self ._a = digitalio .DigitalInOut (board .BUTTON_A )
60
- self ._a .switch_to_input (pull = digitalio .Pull .DOWN )
61
- self ._b = digitalio .DigitalInOut (board .BUTTON_B )
62
- self ._b .switch_to_input (pull = digitalio .Pull .DOWN )
63
-
64
59
# Define switch:
65
60
self ._switch = digitalio .DigitalInOut (board .SLIDE_SWITCH )
66
61
self ._switch .switch_to_input (pull = digitalio .Pull .UP )
@@ -114,6 +109,10 @@ def __init__(self):
114
109
self ._detect_taps = 1
115
110
self .detect_taps = 1
116
111
112
+ # Initialise buttons:
113
+ self ._a = None
114
+ self ._b = None
115
+
117
116
@property
118
117
def detect_taps (self ):
119
118
"""Configure what type of tap is detected by ``cp.tapped``. Use ``1`` for single-tap
@@ -566,6 +565,9 @@ def button_a(self):
566
565
if cp.button_a:
567
566
print("Button A pressed!")
568
567
"""
568
+ if self ._a is None :
569
+ self ._a = digitalio .DigitalInOut (board .BUTTON_A )
570
+ self ._a .switch_to_input (pull = digitalio .Pull .DOWN )
569
571
return self ._a .value
570
572
571
573
@property
@@ -585,6 +587,9 @@ def button_b(self):
585
587
if cp.button_b:
586
588
print("Button B pressed!")
587
589
"""
590
+ if self ._b is None :
591
+ self ._b = digitalio .DigitalInOut (board .BUTTON_B )
592
+ self ._b .switch_to_input (pull = digitalio .Pull .DOWN )
588
593
return self ._b .value
589
594
590
595
@property
You can’t perform that action at this time.
0 commit comments