4x4 matrix keyboard lib for idf

georgecarlo
Posts: 16
Joined: Fri Jan 18, 2019 5:55 am

4x4 matrix keyboard lib for idf

Postby georgecarlo » Mon Feb 25, 2019 7:33 am

Hello community,
I am using 4x4 matrix keypad, i need the library for it. I am using it in in idf. Possible solutions of were can i get the library?? Or map some other keypad resources to work with?/

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: 4x4 matrix keyboard lib for idf

Postby martinayotte » Mon Feb 25, 2019 3:39 pm

georgecarlo wrote:
Mon Feb 25, 2019 7:33 am
Possible solutions of were can i get the library??
Since 4x4 matrix need simple 4 GPIOs as outputs and 4 other GPIOs as input, there is no need for complex library.

georgecarlo
Posts: 16
Joined: Fri Jan 18, 2019 5:55 am

Re: 4x4 matrix keyboard lib for idf

Postby georgecarlo » Tue Feb 26, 2019 4:57 am

can you just suggest me the working so that i can make on my own, i already did with gpio's which is partially done using algorithm i found in youtube, im not sure i understood it fully.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: 4x4 matrix keyboard lib for idf

Postby martinayotte » Tue Feb 26, 2019 3:41 pm

georgecarlo wrote:
Tue Feb 26, 2019 4:57 am
im not sure i understood it fully.
Googling a bit will reveal tons of tutorial, some using libraries, some plain code, like this one :

https://www.baldengineer.com/arduino-ke ... orial.html

georgecarlo
Posts: 16
Joined: Fri Jan 18, 2019 5:55 am

Re: 4x4 matrix keyboard lib for idf

Postby georgecarlo » Fri Mar 01, 2019 5:34 pm

THis is my code implemented from the instructions here http://www.circuitbasics.com/how-to-set ... n-arduino/

can you just help me in this issue, i want to read 4x4 keypad with esp32

Code: Select all

#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"

esp_err_t event_handler(void *ctx, system_event_t *event)
{
    return ESP_OK;
}

void leveltask(void *pvParameter)
{   
    while(1){
    gpio_set_level(16,1); //c1
    gpio_set_level(17,1); //c2
    gpio_set_level(5,1); //c3
    gpio_set_level(18,1); //c4   // default , column check stop 
    gpio_set_level(27,0); //r1
    gpio_set_level(26,0); //r2
    gpio_set_level(25,0); //r3
    gpio_set_level(33,0); //r4
    printf("checking");
    vTaskDelay(10 / portTICK_PERIOD_MS);
    }
}

void app_main(void)
{
    gpio_pad_select_gpio(27); //r1
    gpio_set_direction(27, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(26); //r2
    gpio_set_direction(26, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(25); //r3
    gpio_set_direction(25, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(33); //r4
    gpio_set_direction(33, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(17); //c1
    gpio_set_direction(17, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(16); //c2
    gpio_set_direction(16, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(5); //c3
    gpio_set_direction(5, GPIO_MODE_INPUT_OUTPUT);    
    gpio_pad_select_gpio(18); //c4
    gpio_set_direction(18, GPIO_MODE_INPUT_OUTPUT);
    xTaskCreate(&leveltask, "leveltask", 2048, NULL, 5, NULL);    
    while(1)
    {
    if(gpio_get_level(16) == 0) //column 1 //set level iruka ila store pananuma nu also check loop since printf prints la
    {
      gpio_set_level(27,1); //r1
      {
      if(gpio_get_level(27) && gpio_get_level(16) == 1){printf("button 1 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(17) == 1){printf("button 2 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(5) == 1){printf("button 3 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(18) == 1){printf("button A pressed!");}
      }
      gpio_set_level(26,1); //r2
      {
      if(gpio_get_level(26) && gpio_get_level(16) == 1){printf("button 4 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(17) == 1){printf("button 5 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(5) == 1){printf("button 6 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(18) == 1){printf("button B pressed!");}
      }
      gpio_set_level(25,1); //r3
      {
      if(gpio_get_level(25) && gpio_get_level(16) == 1){printf("button 7 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(17) == 1){printf("button 8 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(5) == 1){printf("button 9 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(18) == 1){printf("button C pressed!");}
      }
      gpio_set_level(33,1); //r4
      {
      if(gpio_get_level(33) && gpio_get_level(16) == 1){printf("button * pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(17) == 1){printf("button 0 pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(5) == 1){printf("button # pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(18) == 1){printf("button D pressed!");}
      }
      gpio_set_level(27,0); gpio_set_level(26,0); gpio_set_level(25,0); gpio_set_level(33,0);
    }
    if(gpio_get_level(17) == 0) //column 2
    {  
      gpio_set_level(27,1); //r1
      {
      if(gpio_get_level(27) && gpio_get_level(16) == 1){printf("button 1 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(17) == 1){printf("button 2 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(5) == 1){printf("button 3 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(18) == 1){printf("button A pressed!");}
      }
      gpio_set_level(26,1); //r2
      {
      if(gpio_get_level(26) && gpio_get_level(16) == 1){printf("button 4 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(17) == 1){printf("button 5 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(5) == 1){printf("button 6 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(18) == 1){printf("button B pressed!");}
      }
      gpio_set_level(25,1); //r3
      {
      if(gpio_get_level(25) && gpio_get_level(16) == 1){printf("button 7 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(17) == 1){printf("button 8 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(5) == 1){printf("button 9 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(18) == 1){printf("button C pressed!");}
      }
      gpio_set_level(33,1); //r4
      {
      if(gpio_get_level(33) && gpio_get_level(16) == 1){printf("button * pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(17) == 1){printf("button 0 pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(5) == 1){printf("button # pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(18) == 1){printf("button D pressed!");}
      }
      gpio_set_level(27,0); gpio_set_level(26,0); gpio_set_level(25,0); gpio_set_level(33,0);
    }
    if(gpio_get_level(5) == 0) // column 3
    {
      gpio_set_level(27,1); //r1
      {
      if(gpio_get_level(27) && gpio_get_level(16) == 1){printf("button 1 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(17) == 1){printf("button 2 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(5) == 1){printf("button 3 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(18) == 1){printf("button A pressed!");}
      }
      gpio_set_level(26,1); //r2
      {
      if(gpio_get_level(26) && gpio_get_level(16) == 1){printf("button 4 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(17) == 1){printf("button 5 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(5) == 1){printf("button 6 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(18) == 1){printf("button B pressed!");}
      }
      gpio_set_level(25,1); //r3
      {
      if(gpio_get_level(25) && gpio_get_level(16) == 1){printf("button 7 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(17) == 1){printf("button 8 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(5) == 1){printf("button 9 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(18) == 1){printf("button C pressed!");}
      }
      gpio_set_level(33,1); //r4
      {
      if(gpio_get_level(33) && gpio_get_level(16) == 1){printf("button * pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(17) == 1){printf("button 0 pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(5) == 1){printf("button # pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(18) == 1){printf("button D pressed!");}
      }
      gpio_set_level(27,0); gpio_set_level(26,0); gpio_set_level(25,0); gpio_set_level(33,0);

    }
    if(gpio_get_level(18) == 0)  //column 4
    {  
      gpio_set_level(27,1); //r1
      {
      if(gpio_get_level(27) && gpio_get_level(16) == 1){printf("button 1 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(17) == 1){printf("button 2 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(5) == 1){printf("button 3 pressed!");}
      else if(gpio_get_level(27) && gpio_get_level(18) == 1){printf("button A pressed!");}
      }
      gpio_set_level(26,1); //r2
      {
      if(gpio_get_level(26) && gpio_get_level(16) == 1){printf("button 4 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(17) == 1){printf("button 5 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(5) == 1){printf("button 6 pressed!");}
      else if(gpio_get_level(26) && gpio_get_level(18) == 1){printf("button B pressed!");}
      }
      gpio_set_level(25,1); //r3
      {
      if(gpio_get_level(25) && gpio_get_level(16) == 1){printf("button 7 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(17) == 1){printf("button 8 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(5) == 1){printf("button 9 pressed!");}
      else if(gpio_get_level(25) && gpio_get_level(18) == 1){printf("button C pressed!");}
      }
      gpio_set_level(33,1); //r4
      {
      if(gpio_get_level(33) && gpio_get_level(16) == 1){printf("button * pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(17) == 1){printf("button 0 pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(5) == 1){printf("button # pressed!");}
      else if(gpio_get_level(33) && gpio_get_level(18) == 1){printf("button D pressed!");}
      }
      gpio_set_level(27,0); gpio_set_level(26,0); gpio_set_level(25,0); gpio_set_level(33,0);
    }
  }
}


Who is online

Users browsing this forum: noweare and 82 guests