@@ -517,8 +517,8 @@ async def main():
517
517
asyncio.run(main())
518
518
```
519
519
Constructor mandatory args:
520
- * ` rowpins ` A list or tuple of initialised output pins.
521
- * ` colpins ` A list or tuple of initialised input pins (pulled down ).
520
+ * ` rowpins ` A list or tuple of initialised open drain output pins.
521
+ * ` colpins ` A list or tuple of initialised input pins (pulled up ).
522
522
523
523
Constructor optional keyword only args:
524
524
* ` buffer=bytearray(10) ` Keyboard buffer.
@@ -554,7 +554,7 @@ async def repeat(tim, uart, ch): # Send at least one char
554
554
555
555
async def main (): # Run forever
556
556
rowpins = [Pin(p, Pin.OPEN_DRAIN ) for p in range (10 , 14 )]
557
- colpins = [Pin(p, Pin.IN , Pin.PULL_DOWN ) for p in range (16 , 20 )]
557
+ colpins = [Pin(p, Pin.IN , Pin.PULL_UP ) for p in range (16 , 20 )]
558
558
uart = UART(0 , 9600 , tx = 0 , rx = 1 )
559
559
pad = Keyboard(rowpins, colpins)
560
560
tim = Delay_ms(duration = 200 ) # 200ms auto repeat timer
@@ -575,6 +575,8 @@ high value. If the capacitance between wires is high, spurious keypresses may be
575
575
registered. To prevent this it is wise to add physical resistors between the
576
576
input pins and 3.3V. A value in the region of 1KΩ to 5KΩ is recommended.
577
577
578
+ ###### [ Contents] ( ./EVENTS.md#0-contents )
579
+
578
580
## 6.4 SwArray
579
581
``` python
580
582
from primitives import SwArray
@@ -588,8 +590,8 @@ are made. The diodes prevent this.
588
590
![ Image] ( ./isolate.png )
589
591
590
592
Constructor mandatory args:
591
- * ` rowpins ` A list or tuple of initialised output pins.
592
- * ` colpins ` A list or tuple of initialised input pins (pulled down ).
593
+ * ` rowpins ` A list or tuple of initialised open drain output pins.
594
+ * ` colpins ` A list or tuple of initialised input pins (pulled up ).
593
595
* ` cfg ` An integer defining conditions requiring a response. See Module
594
596
Constants below.
595
597
@@ -601,32 +603,40 @@ Constructor optional keyword only args:
601
603
that causes actions after a button press, for example on release or auto-repeat
602
604
while pressed.
603
605
606
+ Synchronous bound method:
607
+ * ` keymap() ` Return an integer representing a bitmap of the debounced state of
608
+ all switches in the array. 1 == closed.
609
+
604
610
Class variables:
605
- * ` debounce_ms = 50 `
606
- * ` long_press_ms = 1000 `
607
- * ` double_click_ms = 400 `
611
+ * ` debounce_ms = 50 ` Assumed maximum duration of contact bounce.
612
+ * ` long_press_ms = 1000 ` Threshold for long press detection.
613
+ * ` double_click_ms = 400 ` Threshold for double-click detection.
608
614
609
615
Module constants.
610
- The ` cfg ` constructor arg may be defined as the bitwise or of these constants.
611
- If the ` CLOSE ` bit is specified, switch closures will be reported
612
- * ` CLOSE = const(1) ` Contact closure.
613
- * ` OPEN = const(2) ` Contact opening.
614
- * ` LONG = const(4) ` Contact closure longer than ` long_press_ms ` .
615
- * ` DOUBLE = const(8) ` Two closures in less than ` double_click_ms ` .
616
- * ` SUPPRESS = const(16) ` # Disambiguate. For explanation see ` EButton ` .
617
-
618
- The ` SwArray ` class is subclassed from [ Ringbuf queue] ( ./EVENTS.md#7-ringbuf-queue )
619
- enabling scan codes and event types to be retrieved with an asynchronous iterator.
620
-
616
+ The folowing constants are provided to simplify defining the ` cfg ` constructor
617
+ arg. This may be defined as a bitwise or of selected constants. For example if
618
+ the ` CLOSE ` bit is specified, switch closures will be reported. An omitted event
619
+ will be ignored. Where the array comprises switches it is usual to specify only
620
+ ` CLOSE ` and/or ` OPEN ` . This invokes a more efficient mode of operation because
621
+ timing is not required.
622
+ * ` CLOSE ` Report contact closure.
623
+ * ` OPEN ` Contact opening.
624
+ * ` LONG ` Contact closure longer than ` long_press_ms ` .
625
+ * ` DOUBLE ` Two closures in less than ` double_click_ms ` .
626
+ * ` SUPPRESS ` Disambiguate. For explanation see ` EButton ` .
627
+
628
+ The ` SwArray ` class is subclassed from [ Ringbuf queue] ( ./EVENTS.md#7-ringbuf-queue ) .
629
+ This is an asynchronous iterator, enabling scan codes and event types to be
630
+ retrieved as state changes occur with ` async for ` :
621
631
``` python
622
632
import asyncio
623
633
from primitives.sw_array import SwArray, CLOSE , OPEN , LONG , DOUBLE , SUPPRESS
624
634
from machine import Pin
625
635
rowpins = [Pin(p, Pin.OPEN_DRAIN ) for p in range (10 , 14 )]
626
636
colpins = [Pin(p, Pin.IN , Pin.PULL_UP ) for p in range (16 , 20 )]
637
+ cfg = CLOSE | OPEN # LONG | DOUBLE | SUPPRESS
627
638
628
639
async def main ():
629
- cfg = CLOSE | OPEN # LONG | DOUBLE | SUPPRESS
630
640
swa = SwArray(rowpins, colpins, cfg)
631
641
async for scan_code, evt in swa:
632
642
print (scan_code, evt)
@@ -635,6 +645,12 @@ async def main():
635
645
636
646
asyncio.run(main())
637
647
```
648
+ ##### Application note
649
+
650
+ Scanning of the array occurs rapidly, and built-in pull-up resistors have a
651
+ high value. If the capacitance between wires is high, spurious closures may be
652
+ registered. To prevent this it is wise to add physical resistors between the
653
+ input pins and 3.3V. A value in the region of 1KΩ to 5KΩ is recommended.
638
654
639
655
###### [ Contents] ( ./EVENTS.md#0-contents )
640
656
0 commit comments