|
7 | 7 | import math
|
8 | 8 | import neopixel
|
9 | 9 | import time
|
| 10 | +import touchio |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class Photocell:
|
@@ -50,6 +51,141 @@ def __init__(self):
|
50 | 51 | self.sample = None
|
51 | 52 | self.sine_wave = None
|
52 | 53 |
|
| 54 | + # Define touch: |
| 55 | + self._touch_A1 = None |
| 56 | + self._touch_A2 = None |
| 57 | + self._touch_A3 = None |
| 58 | + self._touch_A4 = None |
| 59 | + self._touch_A5 = None |
| 60 | + self._touch_A6 = None |
| 61 | + self._touch_A7 = None |
| 62 | + |
| 63 | + @property |
| 64 | + def touch_A1(self): |
| 65 | + """Detect touch on capacitive touch pad A1. |
| 66 | +
|
| 67 | + .. image :: /_static/capacitive_touch_pad_A1.jpg |
| 68 | +
|
| 69 | + .. code-block:: python |
| 70 | +
|
| 71 | + from adafruit_circuitplayground.express import cpx |
| 72 | +
|
| 73 | + while True: |
| 74 | + if cpx.touch_A1: |
| 75 | + print('Touched pad A1') |
| 76 | + """ |
| 77 | + if self._touch_A1 is None: |
| 78 | + self._touch_A1 = touchio.TouchIn(board.A1) |
| 79 | + return self._touch_A1.value |
| 80 | + |
| 81 | + @property |
| 82 | + def touch_A2(self): |
| 83 | + """Detect touch on capacitive touch pad A2. |
| 84 | +
|
| 85 | + .. image :: /_static/capacitive_touch_pad_A2.jpg |
| 86 | +
|
| 87 | + .. code-block:: python |
| 88 | +
|
| 89 | + from adafruit_circuitplayground.express import cpx |
| 90 | +
|
| 91 | + while True: |
| 92 | + if cpx.touch_A2: |
| 93 | + print('Touched pad A2') |
| 94 | + """ |
| 95 | + if self._touch_A2 is None: |
| 96 | + self._touch_A2 = touchio.TouchIn(board.A2) |
| 97 | + return self._touch_A2.value |
| 98 | + |
| 99 | + @property |
| 100 | + def touch_A3(self): |
| 101 | + """Detect touch on capacitive touch pad A3. |
| 102 | +
|
| 103 | + .. image :: /_static/capacitive_touch_pad_A3.jpg |
| 104 | +
|
| 105 | + .. code-block:: python |
| 106 | +
|
| 107 | + from adafruit_circuitplayground.express import cpx |
| 108 | +
|
| 109 | + while True: |
| 110 | + if cpx.touch_A3: |
| 111 | + print('Touched pad A3') |
| 112 | + """ |
| 113 | + if self._touch_A3 is None: |
| 114 | + self._touch_A3 = touchio.TouchIn(board.A3) |
| 115 | + return self._touch_A3.value |
| 116 | + |
| 117 | + @property |
| 118 | + def touch_A4(self): |
| 119 | + """Detect touch on capacitive touch pad A4. |
| 120 | +
|
| 121 | + .. image :: /_static/capacitive_touch_pad_A4.jpg |
| 122 | +
|
| 123 | + .. code-block:: python |
| 124 | +
|
| 125 | + from adafruit_circuitplayground.express import cpx |
| 126 | +
|
| 127 | + while True: |
| 128 | + if cpx.touch_A4: |
| 129 | + print('Touched pad A4') |
| 130 | + """ |
| 131 | + if self._touch_A4 is None: |
| 132 | + self._touch_A4 = touchio.TouchIn(board.A4) |
| 133 | + return self._touch_A4.value |
| 134 | + |
| 135 | + @property |
| 136 | + def touch_A5(self): |
| 137 | + """Detect touch on capacitive touch pad A5. |
| 138 | +
|
| 139 | + .. image :: /_static/capacitive_touch_pad_A5.jpg |
| 140 | +
|
| 141 | + .. code-block:: python |
| 142 | +
|
| 143 | + from adafruit_circuitplayground.express import cpx |
| 144 | +
|
| 145 | + while True: |
| 146 | + if cpx.touch_A5: |
| 147 | + print('Touched pad A5') |
| 148 | + """ |
| 149 | + if self._touch_A5 is None: |
| 150 | + self._touch_A5 = touchio.TouchIn(board.A5) |
| 151 | + return self._touch_A5.value |
| 152 | + |
| 153 | + @property |
| 154 | + def touch_A6(self): |
| 155 | + """Detect touch on capacitive touch pad A6. |
| 156 | +
|
| 157 | + .. image :: /_static/capacitive_touch_pad_A6.jpg |
| 158 | +
|
| 159 | + .. code-block:: python |
| 160 | +
|
| 161 | + from adafruit_circuitplayground.express import cpx |
| 162 | +
|
| 163 | + while True: |
| 164 | + if cpx.touch_A6: |
| 165 | + print('Touched pad A6') |
| 166 | + """ |
| 167 | + if self._touch_A6 is None: |
| 168 | + self._touch_A6 = touchio.TouchIn(board.A6) |
| 169 | + return self._touch_A6.value |
| 170 | + |
| 171 | + @property |
| 172 | + def touch_A7(self): |
| 173 | + """Detect touch on capacitive touch pad A7. |
| 174 | +
|
| 175 | + .. image :: /_static/capacitive_touch_pad_A7.jpg |
| 176 | +
|
| 177 | + .. code-block:: python |
| 178 | +
|
| 179 | + from adafruit_circuitplayground.express import cpx |
| 180 | +
|
| 181 | + while True: |
| 182 | + if cpx.touch_A7: |
| 183 | + print('Touched pad A7') |
| 184 | + """ |
| 185 | + if self._touch_A7 is None: |
| 186 | + self._touch_A7 = touchio.TouchIn(board.A7) |
| 187 | + return self._touch_A7.value |
| 188 | + |
53 | 189 | @property
|
54 | 190 | def pixels(self):
|
55 | 191 | """Sequence like object representing the ten NeoPixels around the outside
|
|
0 commit comments