The keyboard on one analog pin does not work

Hello everyone!

I would beg for help!
It is an Arduino and a TM1637 display.
For testing and learning, I used a classically connected keyboard via multiple digital pins and it works satisfactorily, nicely for me.
Now I'm trying to control the 3 x 4 keyboard via one analog pin and it doesn't work.
Can someone explain the code to me step by step?
How to make a mapping for 12 keys?
How can the display show me each key pressed (number under that key)?
I only manage to get the number, but the next time I press, the new number is written over the old one, and not to be moved one place to the left on the display.
For example, I want to enter a 123 number, the program will only enter 1 or only 2 or 3 depending on which key I press.
By the way, I have already used the keys on one analog pin and they work fine, but with this project I don't know how to print on the display.
For now, I don't have any code, only test code, and they refer to the classic keyboard connection.
I would ask for any help to understand what the problem is.
Many, many, many thanks!

Hi, @elpy
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

We will need to se your code and a circuit diagram of how you have the keyboard connected.
Please no Fritzy images, a hand drawn circuit will be fine.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Thank you for the instructions ...
this is the test code:

#include <Arduino.h>
#include <TM1637Display.h>
#include <Keypad.h>

int key = A3;
int num = 0;

#define CLK_0 9
#define DIO_0 8
TM1637Display display_0(CLK_0, DIO_0);

void setup() {
Serial.begin(9600);

pinMode(key, INPUT);

display_0.setBrightness(0);
display_0.clear();
display_0.showNumberDec(0);
delay(250);
display_0.setBrightness(0x0f);
display_0.showNumberDec(num);
}

void loop() {
int value = analogRead(key);
float voltage = value * (5.0 / 1023.0);
// Serial.println(value);
//---------------------- button "1" ------------------------
if ((value > 690) && (value < 700)) {
num = 1;
}
//---------------------- button "2" ------------------------
if ((value > 670) && (value < 680)) {
num = 2;
}
//---------------------- button "3" ------------------------
if ((value > 650) && (value < 660)) {
num = 3;
}
//---------------------- button "4" ------------------------
if ((value > 750) && (value < 760)) {
num = 4;
}
//---------------------- button "5" ------------------------
if ((value > 735) && (value < 745)) {
num = 5;
}
display_0.showNumberDec(num);
}

Hi,
Please read the link in post #2 and follow the instructions on how to post your code.

I hope a circuit diagram is following.
Do you have a DMM?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Did you really read them ??

Sorry for the mistakes ...
What is DMM?

Digital Multimeter.

Tom... :grinning: :+1: :coffee: :australia:

#include <Arduino.h>
#include <TM1637Display.h>
#include <Keypad.h>

int key = A3;
int num = 0;

#define CLK_0 9
#define DIO_0 8
TM1637Display display_0(CLK_0, DIO_0);

void setup() {
  Serial.begin(9600);

  pinMode(key, INPUT);

  display_0.setBrightness(0);
  display_0.clear();
  display_0.showNumberDec(0);
  delay(250);
  display_0.setBrightness(0x0f);
  display_0.showNumberDec(num);
}

void loop() {
  int value = analogRead(key);
  float voltage = value * (5.0 / 1023.0);
  //  Serial.println(value);
  //---------------------- button "1" ------------------------
  if ((voltage > 0.65) && (voltage < 0.80)) {
    num = 1;
  }
  //---------------------- button "2" ------------------------
  if ((voltage > 1.15) && (voltage < 1.25)) {
    num = 2;
  }
  //---------------------- button "3" ------------------------
  if ((voltage > 3.30) && (voltage < 3.40)) {
    num = 3;
  }
  //---------------------- button "4" ------------------------
  if ((voltage > 0.90) && (voltage < 1.00)) {
    num = 4;
  }
  //---------------------- button "5" ------------------------
  if ((voltage > 3.65) && (voltage < 3.75)) {
    num = 5;
  }
  display_0.showNumberDec(num);
}

I hope it's OK now.
I forgot to just put R1, R2, R3 on the resistors ...

I apologize again for the mistakes!

It is not a conventional diagram I can’t read it.
What are the components that are shown as a circle?
They can’t be push buttons because sometimes they have two connections and other times have only one connection.

That is because that is all your code tells it to do. In order to do more you need not only to code the removal of the original digit and show it one place to the right but also you need to decide what will indicate you have finished a multi digit number.

While you can identify different keys by looking at the voltage you can only do this if only one key is held down at any one time. This is a limit of this design. If you hold two or more the the result will be consistent but rubbish.

I use these keys:

The 2 pins upper overlap and the 2 pins lower also overlap.
I only used 2 overlap pins on one side so I didn’t draw all 4 pins on the keys.

ARD is Arduino, more precisely Arduino mini PRO 5 volts.
At the anal input A3 is a 100nf capacitor to reduce interference.
These 7 resistors serve to get some kind of voltage divider.
If necessary I will draw a better scheme?

Thanks for the reply!

Sorry no idea what that means, a schematic shows all the wiring.

You should really look up the word anal.

Yes it would help.

I wrote it wrong, it's not at the anal input but the analog input or pin ... sorry ...

Here's a new scheme:

Thank you for that. I can now see how it works.
I am assuming that you have added a voltage range which specifies nothing is being pressed.

One way to gather the key presses into a single number is to define a character array and place the numbers into them as they are received.

You are much better off using the raw numbers from the analogue converter than converting it to a voltage.

Hi,
Did you write a calibration code that outputted the analog input value to monitor to check your ranges?

What values of value and num do you you get in the serial monitor, if you uncomment them in your code in post#8?

Tom.... :grinning: :coffee: :coffee: :australia:

Up in my post # 3 which is invalid due to badly transferred code on the forum you can see the values I typed as a range for each key, I read them from the serial monitor.
Later I just changed to voltage and wrote the voltages in the valid code.

This Arduino page lists something as an example that might suit me.
https://playground.arduino.cc/Code/OneWireKeyPad/
I just don't know how to put a TM1637 7-segment display instead of an LCD.

I don't understand this part at all, what to write?
" <LiquidCrystal_I2C, 12> KeyPad(Lcd, "

Hi,
Have you looked at the Examples in the IDE that come with the TM1637Display, they should have code to select which digit goes where.
I have a suspicion that;

 display_0.showNumberDec(num);

Loads digit postion zero.
So;

 display_1.showNumberDec(num); 
 display_2.showNumberDec(num);
 display_3.showNumberDec(num);

Will load the other 3 digits.

You need to increase a count everytime you enter a key, the count can then be used to select the appropriate digit.

Tom... :grinning: :coffee: :coffee: :coffee::australia:

Sorry, I didn't put any description in the code.
display_0.showNumberDec(num);
It doesn't set to zero, ignore the zero mark, it's a mark for me because I use multiple displays

In the code, when I press the button, the display shows the number.
That's ok, but when I press the second key, the second number appears on the display but instead of the first,
With LiquidCrystal LCD, it's simple, I type the place where I want the cursor and it writes to me, but I can't do that on this display.