element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Help with Scan code for 4x4 Multiplex keypad with 74hc595/74hc165 Shift Register
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 9 replies
  • Answers 2 answers
  • Subscribers 391 subscribers
  • Views 2801 views
  • Users 0 members are here
  • arduino
Related

Help with Scan code for 4x4 Multiplex keypad with 74hc595/74hc165 Shift Register

obulorn
obulorn over 7 years ago

Helo,

My final aim is to do an 8x8 keypad, presently I have 4x4 keypad available,so am trying out with that. Am using Arduino Uno R3 compatible. My setup is as in the attached: My problem is how to detect the column that went low on key press as to determined the key. Presently any key on Col 0 returns 240; Col1 returns 232; etc (dont know if that is ok. )Please help.

image

Am coding with visual studio 2015 cSharp +Visual Micro My code is as follow:

const int kbdRows = 4;

const int kbdCols = 4;

 

int LatchIn = 3; //165 pin1

int ClockPin = 5; // 595 pin11 & 165 pin2

int DataIn = 2; //165 pin9

int LatchOut = 6; // 595 pin12

int DataOut = 7; //595 pin14

 

int led = 7;

byte mask = 0x80;

byte lastmask = 0x10;

byte  incoming=0 ;

byte dataOuttest;

byte dataIntest;

 

int PinState = 0;

 

char keys[kbdRows][kbdCols] =

{

    { '1','2','3','4' },

    { '5','6','7','8' },

    { '9','0','A','B' },

    { 'C','D','E','F' }

};

 

 

byte KeyDown()

{

    //595 Here

   

    for (int row  = 0; row < kbdRows; row++)

    {

       

                digitalWrite(ClockPin, LOW);

                delayMicroseconds(5);

                digitalWrite(LatchOut, LOW);//

 

                shiftOut(DataOut, ClockPin, LSBFIRST, mask);

                digitalWrite(LatchOut, HIGH);//

                digitalWrite(ClockPin, HIGH);

               

                delay(100);

 

                Serial.println("  ");

                Serial.print("Row: "); // here was to test for Data Shift Out

                Serial.print(row);

 

                Serial.print(" ");

 

                Serial.print("Mask: ");

                Serial.println(mask);

                Serial.println("  ");

                Serial.println(" ");

                delay(100);

 

   

    //165 Here

       

                                

    for (int col = 0; col < kbdCols; col++)

 

    {

             digitalWrite(ClockPin, LOW);

       

                digitalWrite(LatchIn, LOW);

                delayMicroseconds(5);

                digitalWrite(LatchIn, HIGH);

       

                incoming = shiftIn(DataIn, ClockPin, LSBFIRST);

               digitalWrite(ClockPin, HIGH);

 

 

        Serial.print("Col: ");

        Serial.println(col);

        Serial.print("InComing: ");

        Serial.println(incoming);

 

       

    /////if(incoming & mask)/////////////////

    ///{

        /// byte keypress = keys[row][col];

        /// Serial.print("KeyPRESS: ");

    ///    Serial.println(keypress); ////////////// here is my probs, dont know how to return the pressed key with my setup

 

 

    /// }// end of if

       

       

        delay(600);

 

    } // end of col

    if (mask == lastmask)

        mask = 0x80;

    else

    mask = mask >> 1;

 

    } // row end

 

}

 

 

 

 

void setup()

{

 

  /* add setup code here */

    pinMode(ClockPin, OUTPUT);

    pinMode(DataOut, OUTPUT);

    pinMode(DataIn, INPUT);

    pinMode(LatchOut, OUTPUT);

    pinMode(LatchIn, OUTPUT);

 

    digitalWrite(LatchOut, LOW);

   

    digitalWrite(ClockPin, LOW);

    Serial.begin(9600);

 

    digitalWrite(led, HIGH);

   

}

 

void loop()

{

 

  /* add main program code here */

 

void setup()

{

 

  /* add setup code here */

    pinMode(ClockPin, OUTPUT);

    pinMode(DataOut, OUTPUT);

    pinMode(DataIn, INPUT);

    pinMode(LatchOut, OUTPUT);

    pinMode(LatchIn, OUTPUT);

 

    digitalWrite(LatchOut, LOW);

   

    digitalWrite(ClockPin, LOW);

    Serial.begin(9600);

 

    digitalWrite(led, HIGH);

   

}

 

 

void loop()

{

 

  /* add main program code here */

 

 

  KeyDown();

  delay(300);

 

}

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 7 years ago in reply to obulorn +1 suggested
    Hi Obulor, The line /////if(incoming & mask) should not have /// at the beginning, this is commenting it out. Nor should the subsequent lines have the //. Anyway that line if(incoming & mask) (i.e. without…
Parents
  • obulorn
    0 obulorn over 7 years ago

    Please any one using this code should pull down  and Not  pull up as in the attached schematics

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • obulorn
    0 obulorn over 7 years ago

    Please any one using this code should pull down  and Not  pull up as in the attached schematics

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube