Reading a 4x3 matrix problem

I came around a little problem while working on my project.
I tried to read a 4x3 matrix but i can't seem to get it working with a analog pin.
Does anyone have the code and solution to this problem would be nice.

Kind regards Wouter

woujer:
I came around a little problem while working on my project.
I tried to read a 4x3 matrix but i can't seem to get it working with a analog pin.
Does anyone have the code and solution to this problem would be nice.

Kind regards Wouter

What matrix?
A keyboard matrix?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you post your code please?
Tom... :slight_smile:

TomGeorge:
What matrix?
A keyboard matrix?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Can you post your code please?
Tom... :slight_smile:

Nothing super special of a circuit atm. I'm using a arduino UNO and a simple 4x3 keyboard matrix.
I'm still searching for a circuit i can use to fix this. anyway here is the code i used atm.

#include <Key.h>
#include <Keypad.h>

#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

int keys[] ={  //Stores total keypad input
  1, 2, 3, 4, 5, 6, 7, 8, 9, -3, 0, -2}; //"123456789*0#";
int key;  //Stores most recent key pressed
boolean key_lockout=false;
int order[4];
int value=0;
//Initialize
const int vodka=3;
const int gin=4;    //Based on 12v black pumps, 25.3 sec/oz (38 sec/1.5 oz)
const int whiskey=5;
const int tripleSec=6;
const int tequila=7;
const int rum=8;
const int water=9;
const int siroop=10;

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);

  pinMode(vodka, OUTPUT);
  pinMode(gin, OUTPUT);
  pinMode(whiskey, OUTPUT);
  pinMode(tripleSec, OUTPUT);
  pinMode(tequila, OUTPUT);
  pinMode(rum, OUTPUT);
  pinMode(siroop, OUTPUT);
  pinMode(water, OUTPUT);

  digitalWrite(vodka, HIGH);
  digitalWrite(gin, HIGH);
  digitalWrite(whiskey, HIGH);
  digitalWrite(tripleSec, HIGH);
  digitalWrite(tequila, HIGH);
  digitalWrite(rum, HIGH);
  digitalWrite(siroop, HIGH);
  digitalWrite(water, HIGH);

  // ------- 3 blinks of backlight  -------------
  for(int i = 0; i< 3; i++)
  {
    lcd.print("Even gedult...");
    lcd.backlight();
    delay(250);
    lcd.noBacklight();
    delay(250);
    lcd.clear();
  }
  lcd.backlight(); 
}

void loop(){
Beginning:
  {
    //-------- Start/keuze scherm ------------------------------ 
    lcd.clear();
    lcd.setCursor(0,0); //Start at character 4 on line 0
    lcd.print("Whats your order?");
    delay(500);
    lcd.setCursor(0,1);
    lcd.print(" *=Del, #=Enter");
    delay(1000);  
    //-----------------------------------------------------------
    
    value=0;
    for (int x=0; x<3; x++){
      key=getKeypad();  //Get key pressed
      if(key==-1){      //If valid key not pressed restart iteration
        x=x-1;
      }
      else{
        if(key!=14 && key!=12){ //If not CLEAR or ENTER
          value = (10*(value)) + (keys[key]);
          delay(10);
          lcd.clear();
          lcd.setCursor(0,0); //Start at character 4 on line 0
          lcd.print("Item #");
          delay(10);
          lcd.setCursor(6,0);
          lcd.print(value);
          delay(500);
        }
        else if(key==14){ //If ENTER, exit
          x=4;
        }
        else if (key==12){ //If CLEAR, restart
          x=-1;
        }
      }
    }
    lcd.clear();
    lcd.setCursor(0,0); 
    lcd.print("   Press # to");
    delay(10);
    lcd.setCursor(0,1);
    lcd.print("Confirm drink");
    delay(10);
    lcd.setCursor(14,1);
    lcd.print(value);
    do{
      key=getKeypad();
    }
    while(key!=12 && key!=14);
    if(key==12){      //Restart ordering process
      goto Beginning; //Return to the beginning of loop()
    }
    else if(key==14){
      lcd.clear();
      lcd.setCursor(0,0); //Start at character 4 on line 0
      lcd.print("   Confirmed");
      delay(1000);
      switch (value) {
      case 1:    
        longIslandIcedTea();
        
      } 
      delay(5);        // delay in between reads for stability
    }
  }
}

//--------Functions-----------
int getKeypad(){  //Returns which key is pressed
  int ret=-1;
  boolean reset_lockout=false;
  if(analogRead(A0)<120)
    key_lockout=false;
  else if(!key_lockout){
    delay(100);
    ret=15.5-(log((analogRead(A0)-183.9)/58.24)/0.1623);//+0.5;
    key_lockout=true;
  }
  return ret;
}

//    Menu
//Long Island Iced Tea
int longIslandIcedTea(){
  digitalWrite(vodka, LOW);
  delay(80);
  digitalWrite(gin, LOW);
  delay(80);
  digitalWrite(tripleSec, LOW);
  delay(80);
  //Serial.println("In the matrix");
  digitalWrite(tequila, LOW);
  delay(80);
  digitalWrite(rum, LOW);
  delay(80);
  digitalWrite(water, LOW);
  delay(6600);
  digitalWrite(vodka, HIGH);
  delay(6400);
  digitalWrite(water, HIGH);
  digitalWrite(gin, HIGH);
  digitalWrite(tripleSec, HIGH);
  digitalWrite(tequila, HIGH);
  digitalWrite(rum, HIGH);

}

Can you provide a link to your keyboard? A data sheet is very helpful, but a link to where you bought it helps too.

vinceherman:
Can you provide a link to your keyboard? A data sheet is very helpful, but a link to where you bought it helps too.

https://www.addicore.com/v/vspfiles/downloadables/Product%20Downloadables/Project_Interface_Kit/Addicore_12-Key_Keypad_Tutorial.pdf

Hi,
That link shows you how to connect the keyboard to the UNO.
Why are you asking about analog pin connections?
And even code...

Tom... :slight_smile:

TomGeorge:
Hi,
That link shows you how to connect the keyboard to the UNO.
Why are you asking about analog pin connections?
And even code...

Tom... :slight_smile:

I want a 1 analog input not multi input on my UNO that's the problem

I want a 1 analog input not multi input on my UNO that's the problem

Forget that idea.

woujer:
I want a 1 analog input not multi input on my UNO that's the problem

You need to build or find an analog button pad. You have a digital key pad now.

Hi,
Change from a UNO to a MEGA, more I/O and you can then use the 3x4 digital keyboard.

Tom... :slight_smile:

With analog buttons you have a number of buttons that connect a different resistor each to power (press one button at a time only) on one side and the analog pin and another resistor to ground forming a voltage divider. Each button press makes a different voltage on the pin, make sure none are close to any others.