Comments (2)
Not sure this is the best approach, but I just did a brute force translation. Pls let me know if there is a better way:
// **********************************************************************
// Function to translate button hex code returned to expected 0-7 value
int fnTranslateButtonCode (uint32_t dwButton)
{
int i_ButtonTranslated = dwButton >> 16 ;
switch (i_ButtonTranslated) {
case 0x01:
i_ButtonTranslated = 0 ;
break ;
case 0x04:
i_ButtonTranslated = 1 ;
break ;
case 0x10:
i_ButtonTranslated = 2 ;
break ;
case 0x40:
i_ButtonTranslated = 3 ;
break ;
case 0x02:
i_ButtonTranslated = 4 ;
break ;
case 0x08:
i_ButtonTranslated = 5 ;
break ;
case 0x20:
i_ButtonTranslated = 6 ;
break ;
case 0x80:
i_ButtonTranslated = 7 ;
break ;
}
return i_ButtonTranslated ;
}
from tm16xx.
Hello @zapdogster ,
The getButtons() method of the chip-specific class indeed does the work. In your case of the TM1638 LED&KEY module, it is TM1638.cpp that has the implementation. The number of buttons supported depends on the specific chip. While your module has eight buttons, the TM1638 chip supports 8x3 buttons and simultaneous presses. There is another TM1638 module that has a 4x4 keypad. Other chips have different support for buttons, as you can see in this table. To implement a uniform interface the getButtons() method returns a 32-bit value,, representing the state of a maximum of 32 buttons. The LED&KEY module only uses buttons on the K3 pin, which are returned by getButtons() as the third byte of the 32-bit value, giving you buttons 16-23. (The 4x4 button module also returns other values)
The TM16xxButtons_clicks example uses the TM16xx buttons class to report the pressed button. The callback functions receive buttons numbers in the range 0-31, based on their bit position. The easiest way to change the button number to a 0-7 range in for instance fnClick is to simply subtract 16 from the value:
void fnClick(byte nButton)
{
nButton=nButton-16; // change values 16-23 to 0-7
Serial.print(F("Button "));
Serial.print(nButton);
Serial.println(F(" click."));
} // click
Edit: as you noticed the button order may seem less logic. The actual order depends on the wiring on the module. Your method of using a switch statement is a good way, but I would manipulate the button number in the callback function instead of the 32-bit value. My reason is that those callback functions add very useful functionality, such as detecting simultaneous presses, long key presses and double clicks. Therefor if needed I would just make a simple translation function to change the order and call that in the callback functions.
from tm16xx.
Related Issues (20)
- Redefine Pins HOT 1
- Redback 7-segment led and button module with TM1652 HOT 4
- Add pinMode() to sendData() and getButtons() HOT 1
- Example for TM1640 with common anode 8x8 bicolor led matrix? HOT 17
- TM1650 Arduino library for 2 x 7 led display HOT 7
- regarding interfacing of tm1640 HOT 12
- Can I act _as_ a TM1651? HOT 4
- Problem while using this library with ESP32 HOT 3
- Hello Any help on TM1621 HOT 2
- how we can use 4 segment with dot HOT 1
- Another TM1652 device HOT 2
- Halt when useing RP2040 with TM1652 HOT 2
- TM16xxDisplay.cpp bug HOT 1
- Request: Flip 8x8 matrix HOT 18
- Monitoring TM1628 HOT 6
- How do you control the TM1638 discrete LEDS? HOT 2
- Support for TM1618? HOT 14
- Problems with TM1618 HOT 15
- Request: Brightness scaled [0-255] instead of [0-7] HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tm16xx.