Go Down

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

Nick Gammon

I find myself often typing in the same links when answering forum questions, and wanted to automate the process a bit.

Example: http://www.gammon.com.au/interrupts

Previously I had a list of them in one place (on a Stickies document on the Mac) but still had to switch apps, highlight, copy, switch back, paste.

Then with the Leonardo and its ability to emulate a keyboard I saw an opportunity. Here:



A 16-key keypad is hooked up to the Leonardo, and when a key is pressed it sends a pre-configured text item to the keyboard. Assuming the cursor is on a forum message, the link is now promptly inserted.

Code is simple:

Code: [Select]

#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
 
 // Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup ()
{
 // initialize control over the keyboard:
 Keyboard.begin();
}  // end of setup

void loop ()
 {
  byte key =  kpd.getKey();
  if (!key)
    return;
   
 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 ...
     
   } // end of switch
 } // end of loop
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Si

Excellent idea Nick - I could do with one for texting on my mobile phone!
--
My New Arduino Book: http://www.arduinobook.com

martin_bg

That's great Nick,

However I think this is like shooting rabbits with a rocket. I think Arduino is OK for prototyping, but in the spirit of hacking something like http://codeandlife.com/2012/03/03/diy-usb-password-generator/ or http://www.frank-zhao.com/cache/usbbusinesscard_details.php is more educational and not so hard to do as well for a fraction of the price.

Please don't get me wrong, I don't mean to lessen the achievement you have, just my recommendation.

Nick Gammon

Thanks for the links. Actually the Leonardo doubles up as my Leonardo test bed, and I just re-upload the phrase-generator when not being used for something else.

I also have another processor in another room using the "cheap USB" interface, dedicated to supplying a password to a web site that keeps asking for it every 10 minutes, grrrrr, so I thought *&^%$#@ them, I'll hit a button when needed.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

iyahdub

10 LET Loop=Infinite
20 GO TO 10

Graynomad

Rob Gray aka the GRAYnomad www.robgray.com

strykeroz

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 :)
Geoff
"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

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


Yes, but I have OS/X.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

#9
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:
 Keyboard.begin();
 pinMode (ledPin, OUTPUT);
}  // end of setup

void loop ()
 {
 
  // show which messages are active
  digitalWrite (ledPin, alternateMessages ? HIGH : LOW);
 
  byte key =  kpd.getKey();
  if (!key)
    return;
   
 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
   
 else
 
   // 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


Tips:

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);
         Keyboard.releaseAll();
         }
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

uwefed

Very nice idea Nick, specialy for moderators.   ;) ;) ;)

Ciao Uwe

Jantje

Great work nick
As you started starring you can start multiple ties (reflected by multiple leds) to have as many texts as you want.

Best regards
Jantje
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Nick Gammon

Yes, good idea. It will be like a huge custom "boilerplate" generator.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up