gavinlyonsrepo / TM1638plus

An Arduino library to drive TM1638 seven segment modules.
https://gavinlyonsrepo.github.io/
GNU General Public License v3.0
79 stars 25 forks source link

Feature request: Multiple button pressed #12

Closed wunderbaum closed 4 years ago

wunderbaum commented 4 years ago

Hello, thanks alot for adding my simple mqtt-example. Is it possible in any way to detect multiple buttons pressed at the same time? Like 1+2 is pressed simultaneously.

gavinlyonsrepo commented 4 years ago

For which Model?

wunderbaum commented 4 years ago

For the 16 button version. But maybe its handy for all 3 models.

gavinlyonsrepo commented 4 years ago

Model 1 and 3 CAN do it , Model 2 (16 buttons) CANNOT at present but I will make a change .

Model 1 and 3 read buttons function returns a byte where each bit represents a button so 0x01 is button 1 and 0x80 is button 8 so it supports multiple button can be detected 0x81 is buttons 1 and 8 together for example. b7b6b5b4b3b2b1b0. b00000001 = button 1 pressed b10000000 = button 8 pressed b10000001 = button 1 + 8 pressed together

Model TWO also returns a byte but it returns the decimal number of last switch pressed , 1 - 16 . so it CANNOT detect multiple buttons pressed. I will have to write a function which returns a word (16-bit) where each bit corresponds to a switch.

wunderbaum commented 4 years ago

Ah, I see. So there is a need for a second routine beside the "ReadKey16()" for kind of raw data.

gavinlyonsrepo commented 4 years ago

Hi

We have a problem . I have been doing some tests and, If the user presses a certain combination of multiple button at same time it can change the values displayed on the seven segment display. Due to the hardware of the board the different components multiplex lines ( see schematic in the readme) For example if I write 0000-0003 to the unit and do NOTHING else(no button reads nothing) but loop if I then press S1 and S4 together the display changes to 0000-8008. Many combinations of keys do not cause an anomaly only some.

The good news is I have written a function. which returns the full 16 bits of data and the unit can detect multiple presses and display them in the serial monitor based on number read back. Code and info at link:

https://gist.github.com/gavinlyonsrepo/e3485841642e8f47c0d12f229050a034

I will include this in the next update. when i get time to do it. I am not sure how useful it will be if display is changing for certain values. Maybe there is a way to make it work in certain programs by only displaying at certain times or maybe the user does not need every combination of key press. I will have to think about this.

wunderbaum commented 4 years ago

Hey! Thank you, I will test the new version soon! I do not care much if the user presses more buttons and the display does not show the right value. I think this is the limitation of cheap hardware, so don't worry. The user should know himherself which button heshe pressed just a few moments ago.

gavinlyonsrepo commented 4 years ago

Version 1.7 released, it has analternate function which can detect multiple key presses, albeit with the limitations of anomalies displaying on seven segment due to the module sharing the SG-X lines between switches and segments, happens during certain combinations of key presses.

The new function is readKeyTwo() it returns a 16 bit integer.

Where each bit is a switch, /S16 S15 ------------ S2 S1. For example pressing S1 and S4 together gives 9 S1 0000 0000 0000 0001 = 0x0001 S4 0000 0000 0000 1000 = 0x0008 S1 + S4 = 0000 0000 0000 1001 = 0x0009