Go Down

Topic: Forum quick-typer uses Leonardo and keypad for common phrases (Read 6 times) previous topic - next topic


Rob Gray aka the GRAYnomad www.robgray.com


Wow.  That's brilliant Nick.  

I get what martin_bg means (ie to the man with a hammer, every problem is a nail) but I can't help but love this idea.  

Forum mods the world over can now avoid RSI because of your work :)
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Udo Klein

Check out my experiments http://blog.blinkenlight.net

Nick Gammon

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

Yes, but I have OS/X.

Nick Gammon

Oct 22, 2012, 08:28 am Last Edit: Oct 22, 2012, 08:31 am by Nick Gammon Reason: 1
I ended up running out of buttons for all the things I wanted to say <sigh> such as "please don't cross post".

This variation adopts the idea of a "shift key". The "*" key on the keypad now puts the keypad into "shifted" mode. An LED (and resistor) connected to D13 glows to indicate you have the alternate set of messages. Pressing "*" again cancels shift. Also it drops out of shift as soon as you use the shifted message (you could delete that line).

This now lets you have 30 messages rather than 16.

Code: [Select]

// Author: Nick Gammon
// Date: 5th July 2012
// Modified: 22 October 2012

#include <Keypad2.h>

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
 {'1', '2', '3', 'A'},
 {'4', '5', '6', 'B'},
 {'7', '8', '9', 'C'},
 {'*', '0', '#', 'D'},

byte rowPins[ROWS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5}; //connect to the column pinouts of the keypad
const byte ledPin = 13;
boolean alternateMessages = false;

 // Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup ()
 // initialize control over the keyboard:
 pinMode (ledPin, OUTPUT);
}  // end of setup

void loop ()
  // show which messages are active
  digitalWrite (ledPin, alternateMessages ? HIGH : LOW);
  byte key =  kpd.getKey();
  if (!key)
 if (alternateMessages)
   switch (key)
     case '1': Keyboard.println (F("Alternate message A")); break;
     case '2': Keyboard.println (F("Alternate message B")); break;
     case '3': Keyboard.println (F("Alternate message C")); break;

// ... and so on ...

     case '*': alternateMessages = false; break;
     } // end of switch
   // go back to main messages
   alternateMessages = false;
   } // end of if alternate messages
   // normal messages
   switch (key)
     case '1': Keyboard.println (F("http://www.gammon.com.au/interrupts")); break;
     case '2': Keyboard.println (F("http://www.gammon.com.au/i2c")); break;
     case '3': Keyboard.println (F("http://www.gammon.com.au/spi")); break;

// ... and so on ...
     case '*': alternateMessages = true; break;
     } // end of switch
   }  // end of normal messages
 } // end of loop


You can do other things like adding a newline into your message:

Code: [Select]

       Keyboard.println ();

And if you want to arrow back inside a message (eg. do code tags and put the cursor back inside the tags):

Code: [Select]

       for (int i = 0; i < 8; i++)
         Keyboard.press (KEY_LEFT_ARROW);

Go Up