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 Arduino - Two Inputs Using the Keypad.
  • 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 5 replies
  • Subscribers 392 subscribers
  • Views 1788 views
  • Users 0 members are here
Related

Arduino - Two Inputs Using the Keypad.

Former Member
Former Member over 10 years ago

Hey guys,

i am new to arduino. i am currently working on a small project. basically i am using the 4 x 4 keypad for the input and LCD for display. so once the program runs the user enters two value. so first input is 2 digit input which arduino saves in an array and similarly the second input is a four digit input that is saved into the second array. The program runs successfully and reads the first input correctly though the second input does not work.

 

if (int(key1) != 0 and currentState == 1) {

 

switch (key1) {

case '*':

// sets the first array to zero

currentState = 1;

break;

 

case '#':

//saves the value into the first array

//sets the currentState to 2

currentState = 2;

if (currentState = 2){

switch (key1){

case '*':

//sets the second array to zero

currentState = 2;

break;

case '#':

//saves the value into the second array

currentState = 1;

break;

 

case 'A':

//goes back to the menu

break;

 

default:

currentTValue[0] = currentTValue[1];

currentTValue[1] = key1;

break;

}

}

break;

 

case 'A':

//goes back to the menu

break;

 

default:

currentT2Value[0] = currentT2Value[1];

currentT2Value[1] = currentT2Value[2];

currentT2Value[2] = currentT2Value[3];

currentT2Value[3] = key1;

break;

}

}

}

  • Sign in to reply
  • Cancel

Top Replies

  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago +3
    You have the classic beginner mistake of using an assignment where you want to perform a comparison currentState = 2 is an assignment not a compare currentState == 2 is a comparison and will return a true…
  • mcb1
    mcb1 over 10 years ago +1 verified
    if (currentState = 2) needs to be if (currentState == 2) Although I'm unsure why you check when you set it the line above and several lines later. Do you really need line 12 and 13 ? if (int(key1) !…
  • Robert Peter Oakes
    Robert Peter Oakes over 10 years ago in reply to mcb1 +1
    A very good and valid point Mark, I was not intending to deminish your valued input, just focus on the lesser issue of the use of comparison vs assignment operators to help Terry along. And yes, it is…
Parents
  • mcb1
    0 mcb1 over 10 years ago

    if (currentState = 2)

     

    needs to be if (currentState == 2)

    Although I'm unsure why you check when you set it the line above and several lines later.

     

    Do you really need line 12 and 13  ?

     

    if (int(key1) != 0 and currentState == 1) {
    
     switch (key1) {
     case '*':
     // sets the first array to zero
     currentState = 1;
     break;
    
     case '#':
     //saves the value into the first array
    //sets the currentState to 2
     currentState = 2;
    
    if (currentState = 2){
    switch (key1){
    case '*':
    //sets the second array to zero
    currentState = 2;
    break;
    case '#':
    //saves the value into the second array
    currentState = 1;
     break;
    
     case 'A':
     //goes back to the menu
     break;
      
     default:
     currentTValue[0] = currentTValue[1];
     currentTValue[1] = key1;
     break;
     }
    }
     break;
    
     case 'A':
     //goes back to the menu
     break;
      
     default:
     currentT2Value[0] = currentT2Value[1];
     currentT2Value[1] = currentT2Value[2];
     currentT2Value[2] = currentT2Value[3];
     currentT2Value[3] = key1;
     break;
     }
     }
    }

     

     

    For entering code use the >> and select Syntax Highlighting, then C++.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 10 years ago

    if (currentState = 2)

     

    needs to be if (currentState == 2)

    Although I'm unsure why you check when you set it the line above and several lines later.

     

    Do you really need line 12 and 13  ?

     

    if (int(key1) != 0 and currentState == 1) {
    
     switch (key1) {
     case '*':
     // sets the first array to zero
     currentState = 1;
     break;
    
     case '#':
     //saves the value into the first array
    //sets the currentState to 2
     currentState = 2;
    
    if (currentState = 2){
    switch (key1){
    case '*':
    //sets the second array to zero
    currentState = 2;
    break;
    case '#':
    //saves the value into the second array
    currentState = 1;
     break;
    
     case 'A':
     //goes back to the menu
     break;
      
     default:
     currentTValue[0] = currentTValue[1];
     currentTValue[1] = key1;
     break;
     }
    }
     break;
    
     case 'A':
     //goes back to the menu
     break;
      
     default:
     currentT2Value[0] = currentT2Value[1];
     currentT2Value[1] = currentT2Value[2];
     currentT2Value[2] = currentT2Value[3];
     currentT2Value[3] = key1;
     break;
     }
     }
    }

     

     

    For entering code use the >> and select Syntax Highlighting, then C++.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject 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