1 Pin & 6 Buttons - Analog Keyboard

Introduction: 1 Pin & 6 Buttons - Analog Keyboard

About: Software, electronics, do-it-yourself
How to connect six keys with one pin to the microcontroller. It often happens that our circuit is missing free pins. The method to solve this problem is many, for example:

This article can also see here:


1 pin & 6 buttons - Analog Keyboard

Step 1: Components

Step 2: Schematic

Connection of analog keyboard to Arduino.

Step 3: Software

The method to read the key is very simple. Each key gives different output voltage so using the analog-digital converter recognize which key was pressed. Because reading from the analog input may be slightly different, it is safe to check whether the value is in the range.

#define CHECK_KEY( __v0__, __v1__) __v0__ >= (__v1__ - 10) && __v0__ < (__v1__ + 10)
byte GetKeyNumber(int key){
  byte num = 255;
  
  //0, 90, 170, 236, 293, 340
  if( key < 10 ){
    num = 0;
  }else if( CHECK_KEY(key, 90) ){
    num = 1;
  }else if( CHECK_KEY(key, 170) ){
    num = 2;
  }else if( CHECK_KEY(key, 236) ){
    num = 3;
  }else if( CHECK_KEY(key, 293) ){
    num = 4;
  }else if( CHECK_KEY(key, 340) ){
    num = 5;
  }
  return num;
}
Download source code: AnalogKeyboard.ino

Step 4: Testing the Keyboard

wwwGoogle pluseTwitter

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest
    • Big and Small Contest

      Big and Small Contest

    Comments