Pages: [1]   Go Down
Author Topic: Forum quick-typer uses Leonardo and keypad for common phrases  (Read 5838 times)
0 Members and 2 Guests are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged


UK
Offline Offline
God Member
*****
Karma: 13
Posts: 903
Twitter: @simonmonk2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent idea Nick - I could do with one for texting on my mobile phone!
Logged

--
My New Arduino Book: http://www.arduinobook.com

0
Offline Offline
Full Member
***
Karma: 0
Posts: 134
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 351
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Brilliant work as usual , Nick !!
Logged

10 LET Loop=Infinite
20 GO TO 10

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8525
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I love it.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3487
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice, but I would have solved something like this autoit http://www.autoitscript.com/site/autoit/ or autohotkey.
Logged

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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:
       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:
       for (int i = 0; i < 8; i++)
          {
          Keyboard.press (KEY_LEFT_ARROW);
          Keyboard.releaseAll();
          }
« Last Edit: October 22, 2012, 01:31:12 am by Nick Gammon » Logged


BZ (I)
Online Online
Brattain Member
*****
Karma: 266
Posts: 21650
+39 349 2158303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very nice idea Nick, specialy for moderators.   smiley-wink smiley-wink smiley-wink

Ciao Uwe
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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 -

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, good idea. It will be like a huge custom "boilerplate" generator.
Logged


Pages: [1]   Go Up
Jump to: