You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a start for another library that could be for the Circuit Playground Express, or usable across multiple boards. I'm posting the code here so anyone who wants to pick this up has a place to start. The idea is to allow for iteration across all capacitive touch inputs (in the current case, the touch pads on the CPX), and return strings, ints or pin instances for use. It could possibly be written into a class that uses touch state. Or it could be expandable to include all inputs that provide boolean values, such as buttons as well.
As it is, it initialises all of the touch pads as touch pads, which on the CPX means that none of those pads can be used anything else, such as digital outputs, at the same time that this function is called. This may not be an issue in the eventual library, but it's something to be aware of.
The functions are:
def touched_padname(self):
pin = (board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.A7)
touch = tuple(touchio.TouchIn(p) for p in pin)
return ['A{}'.format(i+1) for (i, v) in enumerate(touch) if v.value]
def touched(self):
pin = (board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.A7)
touch = tuple(touchio.TouchIn(p) for p in pin)
return [i for (i, v) in enumerate(touch) if v.value]
This allows for use like the following examples. It is by no means limited to the simplicity of these examples.
for pad in cpx.touched:
print("pad {0} touched!".format(pad))
if 1 in cpx.touched:
print("pad 1 touched!")
if 'A1' in cpx.touched:
print("pad A1 touched!")
COMBO = ('A1', 'A2', 'A5')
if all(pad in cpx.touched for pad in COMBO):
print("UNLOCKED!")
Oh this looks fun! So I see two ways of doing this:
Make an IterableInput class that leverages __iter__, __next__, __getitem__, and __setitem__. This would allow adding some additional functionalities as needed, and the ability to subclass if also needed eventually. Also allow users to create simple collections of iterables, but not sure on the use cases for that.
Leverage the existing CircuitPlaygroundBase._touches list of touch inputs and just creating the properties you mentioned above to iterate through that collection. This wouldn't require any new class to be made, and which maybe will save memory but I don't know the priority for this issue.
Just posting to say I'm actively working on this! Should have a PR soon! I decided to go with option 1 because it gives a little more flexibility with things like accessing inputs based on index or name, as well as initing and deiniting the touchpads so they can be used as other inputs as needed!
This code was designed in response to this issue.
It is a start for another library that could be for the Circuit Playground Express, or usable across multiple boards. I'm posting the code here so anyone who wants to pick this up has a place to start. The idea is to allow for iteration across all capacitive touch inputs (in the current case, the touch pads on the CPX), and return strings, ints or pin instances for use. It could possibly be written into a class that uses touch state. Or it could be expandable to include all inputs that provide boolean values, such as buttons as well.
As it is, it initialises all of the touch pads as touch pads, which on the CPX means that none of those pads can be used anything else, such as digital outputs, at the same time that this function is called. This may not be an issue in the eventual library, but it's something to be aware of.
The functions are:
This allows for use like the following examples. It is by no means limited to the simplicity of these examples.
Opened here from original issue here.
The text was updated successfully, but these errors were encountered: