Tuesday, January 21, 2014

Programming Makey Makey clicks to send strings

Sending a string

One way to send a string instead of a keystroke is to modify the Mouse Button Events in the makey.ino file. To make a left mouse click send 'Hello World':
  1. In the Arduino IDE, open the makey-makey.ino file.
  2. In the main code file, *not* the settings.h, find the lines
  3. if (inputs[i].keyCode == MOUSE_LEFT) {
      Mouse.press(MOUSE_LEFT);
    }
    
  4. Comment out the Mouse.Press line, and replace it with a Keyboard.print
  5. if (inputs[i].keyCode == MOUSE_LEFT) {
      //Mouse.press(MOUSE_LEFT);
      Keyboard.print("Hello World.");
    } 
    
  6. Upload the sketch. Pin A1 is the Makey left-mouse click. Touch the Ground and Pin A1 to try it.

Sending a carriage return with button click

Modify the settings.h file this time, since only one key is being modified. For example, pin A0 defaults to a right-mouse-click...change it to send KEY_RETURN.
int keyCodes[NUM_INPUTS] = {
  // top side of the makey makey board
  KEY_UP_ARROW,      // up arrow pad
  KEY_DOWN_ARROW,    // down arrow pad
  KEY_LEFT_ARROW,    // left arrow pad
  KEY_RIGHT_ARROW,   // right arrow pad
  ' ',               // space button pad
  MOUSE_LEFT,        // click button pad
  // female header on the back left side
  'w',                // pin D5
  'a',                // pin D4
  's',                // pin D3
  'd',                // pin D2
  'f',                // pin D1
  'g',                // pin D0
  // female header on the back right side
  MOUSE_MOVE_UP,      // pin A5
  MOUSE_MOVE_DOWN,    // pin A4
  MOUSE_MOVE_LEFT,    // pin A3
  MOUSE_MOVE_RIGHT,   // pin A2
  MOUSE_LEFT,         // pin A1

  // COMMENT MOUSE_RIGHT TO REPLACE IT WITH KEY_RETURN
  //MOUSE_RIGHT      // pin A0
  KEY_RETURN         // pin A0
};

Sending a carriage in sketch code

Instead or modifying the inits, you can write it in one of the Mouse.press routines. Keyboard.write(KEY_RETURN);

No comments:

Post a Comment