Introduction: Arduino Esplora Mouse

About: I'm still here
The Arduino Esplora is one of the newest Arduino Boards. It is shaped like a game controller, and has built in inputs and outputs. You can read more about it here. I won one on Adafruit's Ask an Engineer, and I decided to build a mouse

Step 1: Get the Code

For some reason Instructables wont let me upload the code today. So you can get it here. UPDATE: Link is updated
Here is how the code works:


Esplora.writeRGB(0, 0, 10);                  
int start = Esplora.readButton(SWITCH_3);    
while(start == HIGH) {                       
  start = Esplora.readButton(SWITCH_3);
}

The Esplora turns sets the light blue to signal it is ready to go. It then sets an infinite loop until the top button is pressed.

JoyX = Esplora.readJoystickX();
JoyY = Esplora.readJoystickY();
Esplora.writeRGB(10, 0, 0);


The Esplora then sets the drift on the X and Y axis on the Joystick and sets the led to red to signal that is done.

int xValue = Esplora.readJoystickX();
int yValue = Esplora.readJoystickY();       
xValue = xValue - JoyX;                     
yValue = yValue - JoyY;                     

The Esplora reads the joystick values and removes the drift.

int JoyButton = Esplora.readJoystickButton();
int button1 = Esplora.readButton(SWITCH_1);  
int button2 = Esplora.readButton(SWITCH_2);  
int button3 = Esplora.readButton(SWITCH_3);  
int button4 = Esplora.readButton(SWITCH_4);  
int slide = Esplora.readSlider();            

The Esplora then reads the buttons

int mousespeed = map(slide, 0, 1023, 10, 0);
int mouseX = map( xValue,-512, 512, mousespeed, -mousespeed); 
int mouseY = map( yValue,-512, 512, -mousespeed, mousespeed); 

The Esplora now maps out the max speed of the mouse, and maps out the value of the mouse movement

if(button3 == LOW){                       
    if(activate == 1) activate = 0;
    else activate = 1;
    delay(500);
  }

If the top button is pressed, the Esplora swaps the value of the variable

if(activate == 1){
If the previously set variable is equal to one, the Esplora runs the loop

Esplora.writeRGB(0 , 10, 0 );                
Mouse.begin();                               

The light is set to green and the Mouse is run

if(JoyButton == LOW || button2 == LOW) Mouse.press(MOUSE_LEFT);
    else Mouse.release(MOUSE_LEFT);


if(button1 == LOW) Mouse.press(MOUSE_MIDDLE);               
else Mouse.release(MOUSE_MIDDLE);

if(button4 == LOW)  Mouse.press(MOUSE_RIGHT);  
else Mouse.release(MOUSE_RIGHT);

Mouse.move(mouseX, mouseY, 0);

The Esplora presses and releases the buttons and moves the mouse using the previously set variables

else {
    Mouse.end();
    Esplora.writeRGB(255, 0, 0 ); 
  }

If the mouse is disabled, the Mouse connection is closed, and the led is set to red.

Step 2: How to Use the Mouse

Using the mouse is simple. I uploaded some pictures I modified from the Arduino Guides to explain how to use the mouse. So when you plug in the mouse, the light will turn blue. This means that it is waiting to calibrate the joystick and get rid of any drift. don't move the joystick and press the top button once. The light will turn red or green depending on how long you hold the button. A red light means the mouse is disabled. To enable the mouse, press the top button, and the light will turn green. When the mouse is enabled, the Joystick moves the mouse, the slider controls the speed of the mouse, and the bottom buttons match up with the buttons on the mouse.
Pocket Sized Electronics

Participated in the
Pocket Sized Electronics

Epilog Challenge V

Participated in the
Epilog Challenge V