t11 - olikraus/m2tklib GitHub Wiki
Tutorial 11: M2tklib Event Source
The "event source" will provide information about any user activities to M2tklib. M2tklib must have an event source, otherwise nothing will happen on the dialog form.
The "event source" is a callback procedure. Some predefined callback procedures already exist (like m2_es_arduino
. This tutorial will provide information how to create a custom event source:
- Template and Structure of the event source
- Serveral examples
A custom event source is required if the input hardware is not supported by the standard event source (input buttons with one ADC port, numeric key pad)
Theory
Template for the Event Source
Return Values if the Event Source Procedure
Internal Debounce Algorithm
List of Return Values
- Note:
M2_KEY_SELECT2
must not be used. Instead useM2_KEY_SELECT
twice.
Using Multiple Event Sources
Examples
All following examples will ignore m2.setPin
/m2_SetPin
. Hardware pins are assumed to be fixed and are "hard coded" in the example software.
Additional Button for the same Event
Input Buttons with Positive Logic
Predefined event handlers assume negative logic for the input buttons. Often a controller has build-in pull-up resistors. This internal resitor can be used to build a simple input button. However, in this case logical 0 means "button is pressed" and logical 1 means "button is not pressed".
On the other hand, many Arduino examples use positive logic for the input buttons (see here: http://arduino.cc/en/tutorial/button). An additional external resistor is required and the logic is inverted: 0 means "button is not pressed" and logical 1 means "button is pressed".
Analog Input
Auto Repeat
Numeric Key Pad
Conclusion
Links
- Previous Tutorial: t10
- Wiki Start Page