31
31
import adafruit_thermistor
32
32
import neopixel
33
33
import touchio
34
- import keypad
35
-
36
34
37
35
__version__ = "0.0.0-auto.0"
38
36
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
39
37
40
38
41
- class KeyStates :
42
- """Convert `keypad.Event` information from the given `keypad` scanner into key-pressed state.
43
-
44
- :param scanner: a `keypad` scanner, such as `keypad.Keys`
45
- """
46
-
47
- def __init__ (self , scanner ):
48
- self ._scanner = scanner
49
- self ._pressed = [False ] * self ._scanner .key_count
50
- self .update ()
51
-
52
- def update (self ):
53
- """Update key information based on pending scanner events."""
54
-
55
- # If the event queue overflowed, discard any pending events,
56
- # and assume all keys are now released.
57
- if self ._scanner .events .overflowed :
58
- self ._scanner .events .clear ()
59
- self ._scanner .reset ()
60
- self ._pressed = [False ] * self ._scanner .key_count
61
-
62
- self ._was_pressed = self ._pressed .copy ()
63
-
64
- while True :
65
- event = self ._scanner .events .get ()
66
- if not event :
67
- # Event queue is now empty.
68
- break
69
- self ._pressed [event .key_number ] = event .pressed
70
- if event .pressed :
71
- self ._was_pressed [event .key_number ] = True
72
-
73
- def was_pressed (self , key_number ):
74
- """True if key was down at any time since the last `update()`,
75
- even if it was later released.
76
- """
77
- return self ._was_pressed [key_number ]
78
-
79
- def pressed (self , key_number ):
80
- """True if key is currently pressed, as of the last `update()`."""
81
- return self ._pressed [key_number ]
82
-
83
-
84
39
class Photocell :
85
40
"""Simple driver for analog photocell on the Circuit Playground Express and Bluefruit."""
86
41
@@ -101,9 +56,10 @@ class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
101
56
_audio_out = None
102
57
103
58
def __init__ (self ):
104
- self ._button_pins = [board .BUTTON_A , board .BUTTON_B ]
105
- self ._keys = keypad .Keys (self ._button_pins , value_when_pressed = True , pull = True )
106
- self ._states = KeyStates (self ._keys )
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 )
107
63
108
64
# Define switch:
109
65
self ._switch = digitalio .DigitalInOut (board .SLIDE_SWITCH )
@@ -610,8 +566,7 @@ def button_a(self):
610
566
if cp.button_a:
611
567
print("Button A pressed!")
612
568
"""
613
- self ._states .update ()
614
- return self ._states .pressed (0 )
569
+ return self ._a .value
615
570
616
571
@property
617
572
def button_b (self ):
@@ -630,27 +585,7 @@ def button_b(self):
630
585
if cp.button_b:
631
586
print("Button B pressed!")
632
587
"""
633
- self ._states .update ()
634
- return self ._states .pressed (1 )
635
-
636
- @property
637
- def were_pressed (self ):
638
- """Returns a set of the buttons that have been pressed
639
-
640
- .. image :: ../docs/_static/button_b.jpg
641
- :alt: Button B
642
-
643
- To use with the Circuit Playground Express or Bluefruit:
644
-
645
- .. code-block:: python
646
-
647
- from adafruit_circuitplayground import cp
648
-
649
- while True:
650
- print(cp.were_pressed)
651
- """
652
- self ._states .update ()
653
- return {("A" , "B" )[i ] for i in range (2 ) if self ._states .was_pressed (i )}
588
+ return self ._b .value
654
589
655
590
@property
656
591
def switch (self ):
0 commit comments