3 Replies Latest reply on May 17, 2018 10:34 AM by 14rhb

    How can I control a 6x5 keypad with Modifiers?

    james.battie

      Hi everyone,

       

      I'm asking for some much needed help controlling a 6x5 keypad w/ modifiers (shift key, backspace, space, enter...etc). I have built a circuit that allows use for only one pin on the Arduino Uno. I have all 30 keys responding to key press but I cannot activate the keypad modifiers. I especially need the shift key to function because this keypad has dual sequence key presses (some of the key presses have letters and numbers). I also need to latch the letters and numbers in memory. Can anyone help?

       

      My code is as follows:

       

      #define KEY_UP_ARROW, 0xDA

      #define KEY_DOWN_ARROW, 0xD9

      #define KEY_LEFT_SHIFT, 0x81

      #define KEY_BACKSPACE, 0x82

      #define KEY_SPACE, 0x20

       

      #include <Keyboard.h>

       

      char* keypressed;

      int keyboardPin = A0

      int keyboardValue;

      int keypressedreleaseALL();

       

      void setup(){

           Serial.begin(9600);

           deley (200);

      }

       

      void loop() {

           keyboardValue = analogRead(A0);

       

           while(keyboardValue<25) {

           keyboardValue = analogRead(A0);

           delay(50);

       

      if ((keyboardValue <215) && (keyboardValue >212)) (keypressed = "A"); this is start of code

       

       

       

      if((keyboardValue <565) && (keyboardValue >563)) (keypressed = "KEY_LEFT_SHIFT"); end of code

       

           Serial.println (keypressed);

           delay(1000);

       

      }

        • Re: How can I control a 6x5 keypad with Modifiers?
          14rhb

          Hi James,

           

          Can you possibly post your circuit diagram to help us provide the right help for you? Is this a circuit you've designed yourself or one that you are copying from an article?

           

          It looks like you are using the analogue input pin of the Arduino and each key press will likely give a different voltage based on an external resistance ladder.

           

          Rod

          2 of 2 people found this helpful
            • Re: How can I control a 6x5 keypad with Modifiers?
              james.battie

              Hey Rod,

               

              I apologize for not responding right away (School, work and life). I really do appreciate your much needed help. I have designed this circuit but I had some helpful ideas from others. What I'm looking for is some help writing a code that will control key press (shift_key). The circuit is below.

              1 of 1 people found this helpful
                • Re: How can I control a 6x5 keypad with Modifiers?
                  14rhb

                  James,

                   

                  No need to apologise - there is always something that gets in the way of doing electronics ! Thanks for the photos, makes it easier to see what you are doing. I looked around the internet and found this diagram [on Google  ] which is sort of what you are doing I guess. I've had a think about it and share my thoughts below - don't take them to be 100% correct as I've never tried this before ! Hopefully someone on Element14 will have and can also add comment to help you.

                   

                  Arduino keypad with 1 Analog pin – Ziggy's of the world

                  I can see how an individual key would change the resistive divider:

                   

                  'C' button would short x1 to y4 (gnd) and so the divider would be (390R + 390R + 390R divided by 390R + 390R + 390R + 4k7 ). The voltage to the ADC would be ~0.2 * V

                   

                  '1' button would short x2 to y1 so divider chain would be (390R + 390R + 1k5 + 1k5 + 1k5 divided by 390R + 390R + 1k5 + 1k5 + 1k5 +4k7 ). The voltage to the ADC would be ~0.53 * V

                   

                  I think while you will be able to use multiple keys anything that uses the same row or column wouldn't have an effect. e.g. Pressing 'C' and '0' would behave as just the 'C'. Pressing '0' and '3' would behave as just pressing the '3'.

                   

                  If you pressed buttons that were not in the same row or column then you would get some different values e.g. 'C' and '3' would effectively give you 0v at R8 (assuming ADC input impedance is high).

                   

                  At this point I might go for the empirical approach - try it out and see what values I get and use those in your code as limits. Something like this:

                  void loop() {
                   
                       while(1) {
                       keyboardValue = analogRead(A0);
                  
                       Serial.println(keyboardValue);
                       delay(100); 
                       }
                  }

                   

                  The issue I would see would be that the shift key would also make your existing single key values incorrect. You will likley have to do a second test on all keys of interest for their values with the shift button held down.

                   

                  Good luck.

                   

                  Rod