loading
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

About This Instructable

111views

3favorites

License:

Bio: Software, electronics, do-it-yourself
More by adachsoft:DIY USB Charger for Your Phone - LM2596 DIY WIFI RC Car With ESP8266 and Arduino IDE Control Any Devices Using Raspberry PI and PCF8574, Relay Module 
Add instructable to: