Ardu? No!MTobjectsButton setsMTanalogButtons ≫ Test 2

MTanalogButtons: Test 2
Event management for Uno, Nano, Mega

Number or character

This program tests the callback functions of the MTanalogButtons object.

Complete program example

// MTanalogButtons basic test with characters display

#include <MTobjects.h> // V1.1.0 See http://arduino.dansetrad.fr/en/MTobjects

// You must give the pin for analog reading
const uint8_t PIN = A5; // Change A5 to A0..A7 depending on the case
//
// You must choose the voltage reference to use for the conversion
// DEFAULT: for Vcc
// INTERNAL: 1.1V for Nano/Uno
// INTERNAL1V1: 1.1V for Mega
// INTERNAL2V56: 2.56V for Mega
// EXTERNAL: to use AREF
#define REFERENCE INTERNAL
//
// You must give the console transfer rate
#define BAUDS 115200 // 115200 recommended, but you can put 9600
// Don't forget to set the console to 115200 bauds

const word THRESHOLDS_TABLE[] = {942, 838, 797, 709, 618, 571, 471, 369, 316, 203, 87, 28, 0}; // Comparison threshold values


//   1  2  3
//   4  5  6
//   7  8  9
//   *  0  #


const char keys[] = { // Match for display
    'X', // Corresponds to no support
    '#','0','*', // Key # returns 1...
    '9','8','7',
    '6','5','4',
    '3','2','1',
    };

void display(byte key) // Called when you press a key
{
  Serial.print(keys[key]); // Associated character display
}

void release(void) // Called when you drop all the keys
{
  Serial.println();
}

MTanalogButtons Keypad(PIN, THRESHOLDS_TABLE, display, release); // Implementation of keypad

void setup()
{
  Serial.begin(BAUDS);
  analogReference(REFERENCE); // Allows you to choose the voltage reference
}
  
void loop(){}