finger mouse

25
FINGER MOUSE By Chi-Wei Huang Ting-Fu Chen Yi-Chung Tseng Final Report for ECE 445, Senior Design, Fall 2015 TA: Stephen Hall 9 December 2015 Project No. 47

Upload: others

Post on 31-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: FINGER MOUSE

FINGER MOUSE

By

Chi-Wei Huang

Ting-Fu Chen

Yi-Chung Tseng

Final Report for ECE 445, Senior Design, Fall 2015

TA: Stephen Hall

9 December 2015

Project No. 47

Page 2: FINGER MOUSE

ii

Abstract

The aim of our project is to develop a device which is allowing the presenters to control the

mouse cursor sway from their notebooks, especially without a desk. It is wireless, wearable, small and

light enough to wear around. This device is including two parts. The first part includes power supply

system, Arduino microcontroller, Bluetooth transmitter and sensors, which are gyroscopes and

accelerometers. This part will be worn on the user’s hand. The other part will connect to the computer

and encompass a Bluetooth and another Arduino microcontroller.

At first, we hope to use position tracking technique to develop this device. However, after

double integrating form acceleration to position, we found that the error is too large to be used.

Therefore, we change to use the rotation angle and direction to control the mouse cursor and finally

succeed.

Page 3: FINGER MOUSE

iii

Contents 1. Introduction .............................................................................................................................................. 1

1.1 Statement of Purpose ......................................................................................................................... 1

1.2 Functions and Features ....................................................................................................................... 1

1.2.1 Functions ...................................................................................................................................... 1

1.2.2 Features ....................................................................................................................................... 1

2. Design ........................................................................................................................................................ 2

2.1 Device Illustration and Appearance .................................................................................................... 2

2.1.1 Illustration .................................................................................................................................... 2

2.1.2 Appearance .................................................................................................................................. 2

2.2 Block Diagram ..................................................................................................................................... 3

2.3 Flow chart ........................................................................................................................................... 4

2.4 Power Supply System .......................................................................................................................... 4

2.4.1 System Diagram ........................................................................................................................... 5

2.4.2 Power Converter Circuit: .............................................................................................................. 5

2.4.3 Charging Circuit ............................................................................................................................ 6

2.4.4 Layout of PCB ............................................................................................................................... 7

2.5 Movement Detector ........................................................................................................................... 8

2.5.1 MPU6050 ..................................................................................................................................... 8

2.5.2 Bluetooth Transmitter ................................................................................................................. 9

2.6 Controller .......................................................................................................................................... 10

2.6.1 Bluetooth Receiver ..................................................................................................................... 10

2.6.2 Computer Program .................................................................................................................... 11

3. Requirement Verification and Final Result ............................................................................................. 12

3.1 Requirement and Verification Table ................................................................................................. 12

3.2 Final Result ........................................................................................................................................ 14

3.2.1 Power Supply ............................................................................................................................. 14

3.2.2 Computer Program .................................................................................................................... 14

4. Costs ........................................................................................................................................................ 15

4.1 Parts .................................................................................................................................................. 15

4.2 Labor ................................................................................................................................................. 15

5. Conclusion ............................................................................................................................................... 16

Page 4: FINGER MOUSE

iv

5.1 Accomplishments .............................................................................................................................. 16

5.2 Ethical considerations ....................................................................................................................... 16

5.3 Future work ....................................................................................................................................... 16

References .................................................................................................................................................. 17

Appendix A Java code for the computer driver.................................................................................... 18

Page 5: FINGER MOUSE

1

1. Introduction

1.1 Statement of Purpose We noticed that presenters always need somebody to help him/her control the Power-point.

Although some of them can deal with this by a laser pointer. However, if they want to draw pictures,

present a video, or do some other kinds of interaction with the listeners, they have to walk back to their

computer to achieve this, which waste a lot of time and interrupt the presentation.

So, our idea is to invent a wireless wearable mouse, which is small and light enough to wear

around, while allowing the presenters to control the computer curser away from their PCs, even without

a desk.

1.2 Functions and Features

1.2.1 Functions

The main idea of this device is to control the mouse cursor on the computer with the gyroscopes

and accelerometers wirelessly. This device provides the user with benefits that include:

The device is power by a rechargeable battery, which can be charge with the computer via the

USB port.

Move the mouse cursor by rotating his/her hand while wearing this device.

Click the cursor by making a clicking movement while wearing this device.

Can be operated on any kind of surface or even without a platform.

Wireless and can be functional normally up to 10 meters.

Support multiple computer operating system, including Windows7/8 and MacOS.

1.2.2 Features

This device has many features that make it unique and functional. These features include:

Much more fashion than using normal mouse or laser pointer.

Small, light and easy to bring.

A rechargeable battery that can support the device for at least one hour and may be charge by

the computer with the USB port.

If needed, the user can define his/her own gesture by programming on the computer.

An on/off switch for user that he/she may use our device and the keyboard in the same time.

Longer life-time because there is no clicking button so won’t have physically consumption while

clicking.

Page 6: FINGER MOUSE

2

2. Design

2.1 Device Illustration and Appearance

2.1.1 Illustration

▲ Figure 2.1.1 – Design of the device

2.1.2 Appearance

▲ Figure 2.1.2 – The realistic device

Page 7: FINGER MOUSE

3

2.2 Block Diagram There are two separate parts in our project. One is on user’s hand which includes power supply

system and movement detector. Movement detector has gyroscopes, accelerometers, microcontroller

and Bluetooth transmitter. And the other one is controller which contains microcontroller and Bluetooth

receiver will connect with the computer. Figure 2.2 is a diagram of our whole system. The solid line

represents the power path and the dotted line means the signal path.

▲ Figure 2.2.1 – Block diagram of the overall system

Page 8: FINGER MOUSE

4

2.3 Flow chart

▲ Figure 2.2.2 – Flowchart of the overall system

2.4 Power Supply System The basic requirement of our power converter is providing sufficient power for other subsystem

like Arduino, sensors and blue-tooth module. Consequently, it must provide about 5V output voltage

and 100mA output current to support the whole device. To get high efficiency, the better choice of

power converter is switch mode power converter instead of LDO.

Moreover, because the finger mouse is a wireless and wearable device, button battery is our

best choice to be the voltage source in our project. Finally we use LIR2450, a rechargeable button cell,

which can provide 3.4-4.2 Volt . To convert battery voltage to the proper value. We choose the step-up

converter L6920D, which allow the wide range of input voltage and output 5 or 3.3V output voltage. For

the recharging part, I choose to use MCP73831, a charge management chip for li-ion battery, to

construct the circuit.

Implement cursor

“Move” motion

Bluetooth Receiver

receives data

Arduino

microcontroller signal

processing

YES

Click NO

Implement cursor

“Click” motion

Arduino microcontroller

processes data

Start

Gyroscope/Accelerometer

start detecting signal

ON

Power switch OFF

Bluetooth Transmitter

sends data

YES

NO

Move

Page 9: FINGER MOUSE

5

2.4.1 System Diagram

▲ Figure 2.4.1 – block diagram for power supply system

2.4.2 Power Converter Circuit:

Lx: Connect with input inductor and battery. To keep the high efficiency, the ESR of the input

inductor must be low enough. I choose Panasonic ELL6SH series inductor. And the range of

recommend value in the datasheet is 5uH to 40uH. I chose 10uH to be the input inductor.

LBI: This pin is low battery voltage detection. The voltage connected to this pin will be

compared with the bandgap voltage(1.23V), if it is smaller than bandgap voltage, LBO output

pin will become logical 1. Consequently, we can build a low voltage reminder system with this

detecting system.

F.B: The formula provided in the datasheet indicate that:

After test the circuit practically, the value of output voltage is much different with the

theoretic value. So I choose R4 = 280k and R5=100k to get the 5V output.

Vout: The output voltage would be about 5V with small ripple.

Page 10: FINGER MOUSE

6

▲ Figure 2.4.2 – Schematic of the power converter circuit s

2.4.3 Charging Circuit

This circuit allow users directly charging the battery by using the USB port on the laptop or

computer. The basic design is as same as the application circuit in MCP73831 datasheet.

▲ Figure 2.4.3.1 - Schematic of the battery charging circuit

Page 11: FINGER MOUSE

7

2.4.4 Layout of PCB

▲ Figure 2.4.4.1 – PCB layout of the power converter and battery circuit

▲ Figure 2.4.3.2 – Realistic PCB board of the power converter and battery circuit

Page 12: FINGER MOUSE

8

2.5 Movement Detector

2.5.1 MPU6050

The MPU6050 sensor contains an accelerometer and a gyroscope in a single chip. It contains 16-

bits analog to digital conversion hardware for each channel. Therefore, it captures the x, y, and z

channel at the same time and has the sample rate of 9600Hz. The sensors detect analog data and use its

internal ADC to transfer them into digital data, finally interface with the Arduino through I2C-bus.

We use two MPU6050 as our sensors to detect the user’s movement. The way to activate two

MPU6050 at the same time is to use the pin “AD0” selects between I2C address 0x68 and 0x69. That

makes it possible to have two MPU6050 working together in our project. Just need to connect AD0 of

MPU6050-1 to 5V and connect AD0 of MPU6050-2 to GND.

▲ Figure 2.5.1.1- Wire connection between sensors and microcontroller

Page 13: FINGER MOUSE

9

▲ Figure 2.5.1.2 – Sensors on the fingers

2.5.2 Bluetooth Transmitter

The Bluetooth transmitter is constructed with an Arduino Pro Mini microcontroller and a HC-05

Bluetooth serial module, both of them are powered by 5V from the power supply circuit. The Arduino

Pro Mini will collect the raw data from the sensors and use serial transmission protocol to transmit

the data to the Bluetooth module. The transmitter module will send the data with baud rate 9600bps

to the receiver.

The Arduino Pro mini is a module with core microcontroller ATmega328P, it should be powered

with 5V, and running at 16MHz with external resonator (0.5% tolerance). The specific pin we used is

described as follow:

- A4 and A5

The sensors uses I2C protocol to send digital data to the Arduino, so they are connect to the

special analog pin A4 (SDA) and A5 (SCL) as I2C input, pull-up circuit is added to make sure

the digital data is correct.

- D4 and D5

The Bluetooth module of the transmitter is set as a “master”, it will try to connect to its

slave whenever it is power on. In our program, We use software defined serial port to set

the digital pin D4 and D5 as Tx and Rx, which are connected to the Rx and Tx of the

Bluetooth module.

Page 14: FINGER MOUSE

10

▲ Figure 2.5.2 – Schematic of the Arduino Pro mini and Bluetooth transmitter

2.6 Controller

2.6.1 Bluetooth Receiver

Includes an Arduino UNO microcontroller and a HC-05 Bluetooth module, both of them are

power by 5V from the computer USB port.

The Bluetooth receiver module is set as a “slave”, it is always power on while waiting to be

connection by the master. After being connected, it will receive the transmitted data and input them

into the Arduino microcontroller. The Arduino is connecting to the computer through the USB port, so

we print out all of the received data one the serial monitor and use JAVA program to deal with it.

Page 15: FINGER MOUSE

11

▲ Figure 2.6.1 – Received data printed on the serial monitor

2.6.2 Computer Program

We wrote the Java program to accomplish everything we need including analyze the raw data

from the sensors, use those data to control the cursor and demonstrate the movement of sensors on

the screen. We illustrate some cuboids to represent the sensors. (Figure 2.5.1) While the user rotates

the sensors, the cuboids on the screen will also rotate.

▲ Figure 2.6.2 – 3D models of the sensors constructed based on the received data

Page 16: FINGER MOUSE

12

Moreover, of course, we also need to use this program to control to analyze the data and then

control the cursor on the screen. In Java, there is a class “Robot” can be used to generate native system

input events for the purpose of test automation, self-running demo, and other applications where

control of the mouse and keyboard is needed. Briefly speaking, it can control the mouse and keyboard

events by the computer itself. Here is the flow chart of the code. (The entire code is in the appendix A)

3. Requirement Verification and Final Result

3.1 Requirement and Verification Table

Requirement Verification points 1. Power Supply a. DC/DC converter should be

able to provide 5V +/- 0.25V output voltage for Bluetooth transmission and microcontroller.

b. DC/DC converter should be able to provide 60mA +/- 3mA output current.

1. Power Supply a. Connect the power supply with

50 ohms load resistor and it can provide 4.73 average output voltage with 0.14 Vpp ripple.

b. Connect the power supply with 50 ohms load resistor and it can provide 94.6mA output current.

20

2. Charging circuit a. Charging the battery with

500mA current.

2. Charging circuit a. Connect the charging circuit

with the battery which is out of energy, and there is only 242mA current go through the battery.

20

Robot Construct a robot object in the coordinate system of primary screen first.

Get location Get the information of cursor, which represents the location, and store it as a variable.

Get data Get the data from the Arduino microcontroller.

Analyze the data After getting the data, program will analyze that user is moving or clicking the cursor.

Move or Click the mouse After analyzing, program will move or click the cursor on the screen.

Avoid repeating Set up delay to avoid repeating the same movement.

Page 17: FINGER MOUSE

13

3. Sensors a. Gyroscopes should be able to

measure 3-axis angular rate at minimum value 30°/s and

maximum value 245°/s.

b. Accelerometer should be able to measure 2-axis (no z axis) acceleration at minimum value 0.1m/s2 maximum value 3m/s2.

3. Sensors a. Rotate the gyroscope at

angular rate 30°/s and 245°/s,

we can read the correspond data value from the sensor by printing the output on the monitor.

b. Move the accelerometer at acceleration 0.1m/s2 and 3m/s2, we can read the correspond data value from the sensor by printing the output on the monitor.

15

4. Microcontroller External Clock a. The external oscillator should

provide 16MHz clock frequency for the ATmega328P to assure the working appropriately.

4. Microcontroller External Clock a. Connecting the VCC, GND to

the Arduino and use an oscilloscope to check the oscillator’s frequency is about 16MHz.

5

5. Bluetooth Transmission a. The Bluetooth transmitter

should collect data and transmit it to the microcontroller in baud rate 9600 (bps).

b. The Bluetooth transmitter should be able to transmit data within 10 meters.

5. Bluetooth Transmission a. Transmit data by

microcontroller to Bluetooth receiver and transmit it back to controller. We receive and transmit 9600 bits per second.

b. Increasing the distance between the transmitter and the receiver, the maximum average transmission distance is 7.5m.

25

5. Driver a. Driver on computer should

catch the specific moving signals and operate the cursor with rotation, clicking and dragging.

5. Driver a. Transmit data to the computer

through USB and observe the movement of the cursor. Able to do clicking and drifting cursor movement, heavy lag happen when trying dragging.

15

Page 18: FINGER MOUSE

14

3.2 Final Result

3.2.1 Power Supply

Efficiency: In the condition with full load, including Arduino and all sensors, the output voltage

is 4.73V and output current is 65mA. In addition, the battery voltage is 4V and battery current

is 108mA.

The power efficiency ŋ =0.37

0.432= 85.5%

▲ Figure 3.2.1 – Output voltage of the power supply

Battery lifetime and charging time: the battery capacitor is 120mAh. We can get the battery

lifetime T =120

108= 1.11 ℎ𝑜𝑢𝑟 = 66.6 𝑚𝑖𝑛𝑢𝑡𝑒𝑠

Battery charging time: Tc =120

242= 0.495 ℎ𝑜𝑢𝑟 = 29.5 𝑚𝑖𝑛𝑢𝑡𝑒𝑠

3.2.2 Computer Program

Able to do cursor drifting with hand rotation, and left/right finger clicking with finger

movement. Dragging fails due to heavy lagging, because dragging is viewed as a sequence of continuous

robot input instruction of cursor drifting and clicking, it gives too much workload to the computer

processor. Dragging from left to right ends in discontinuous point instead of a line.

Page 19: FINGER MOUSE

15

4. Costs

4.1 Parts

Part Manufacturer Cost per unit($)

Quantity Actual Cost ($)

L6920DTR STMicroelectronics 2.62 1 2.62

MCP73831 Microchip Technology 0.56 1 0.56

ELL-6SH100M Panasonic 1.13 1 1.13

LIR2450 battery - 1.75 4 7.00

Battery holder - 0.81 1 0.81

RC0603FR-XX Yageo 0.1 8 0.8

CL series capacitor Samsung 0.1 3 0.3

LTST-C230YKT(LED) Lite-On inc. 0.36 2 0.72

Micro-usb connector - 0.72 1 0.72

Push button switch E-switch 3.13 1 3.13

Rocker switch CW industries 1.91 1 1.91

Arduino UNO Atmel 20 1 20

Arduino Pro mini 5V Atmega328P

Atmel 2.22 1 2.22

Bluetooth module HC-05

Innogear 6.45 2 12.9

Gyroscope/accelerometer GY-521 MPU-6050

Kootek 3.25 2 6.5

Shooting Glove 9.99 1 9.99

Subtotal 71.31

4.2 Labor Name Hourly rate Total hour invested Total = Hourly

Rate*2.5*Total hours

Chi-Wei $35.00 120 $10500

Ting-Fu $35.00 120 $10500

Yi-Chun $35.00 120 $10500

Subtotal $31500

Total cost = parts cost + labor cost = $71.31 + $31500 = $31571.31

Page 20: FINGER MOUSE

16

5. Conclusion In Summary, the final function of our device is similar to the concept we constructed at the beginning of

the semester. There are some functions we cannot implement very well like drag and some gesture.

Because the hardware part of our project is very complete. If we can improve the algorithm of data

processing, we think that our device will be more powerful and practical.

5.1 Accomplishments The finger mouse controls the mouse cursor with rotation and consequently implement the 4-

direction drift and clicking.

The wireless transmission distance can attend to 7.5 meters and use our device without desk.

A full-charged battery can support the device for at least one hour.

5.2 Ethical considerations It is very important to follow the rules of the IEEE code of Ethics while we are designing

anything. As an engineer, we can't just develop new products and then ignore the safety, health and

welfare of the public. There are also various aspects that we must keep in mind all the time.

The first one of those aspects is that we have to disclose promptly factors that might endanger

the public or the environment. Meanwhile, we also must avoid injuring others, their property,

reputation, or employment by false or malicious action. In other words, it's our responsibility as

engineers to confirm our product is safe enough for people to use. A couple of safety issue of our

product would be the circuit short and eventually leads to burn while user is using. Therefore, while

designing, we have to make sure that the circuit would not be short. What’s more, on the computer

program, the most important issue is the safety. We have to guarantee that the program we wrote must

be safe enough that won’t be attack by other people.

In our project, we can confirm that our device is safe and environmentally friendly enough. We

use a rechargeable battery as power supply because using normal battery is not good to the

environment. And all of our circuit is necessary, which means we didn’t waste any resource. On the

computer program, the easiest way to avoid attacking is not to interact with other programs. Therefore,

after testing, we have made sure that the program won’t be control by other people via the internet or

other programs.

5.3 Future work To implement drifting motion by processing data from accelerometers instead of gyroscope’s

rotation.

Eliminate light vibration and small movement of human body and consequently reduce the

noise of data.

To implement more useful gestures by improving the algorithm of data processing.

Design more efficient power supply to reduce power loss.

Page 21: FINGER MOUSE

17

References

[1] 1V HIGH EFFICIENCY SYNCRONOUS STEP UP CONVERTER. [Datasheet]. Available:

http://www.st.com/web/en/resource/technical/document/datasheet/CD00002171.pdf

[2] PowerStream Li-ion Button Cell Battery Lir2450. [Datasheet]. Available:

http://www.powerstream.com/p/Lir2450.pdf

[3] MCP73831/2, Miniature Single-Cell, Fully Integrated Li-Ion, Li-Polymer Charge

ManagementControllers. [Datasheet]. Available:

https://cdn.sparkfun.com/datasheets/Dev/Arduino/Shields/MCP738312.pdf

[4] HC-05, Bluetooth to Serial Port Module. [Datasheet]. Available:

http://www.robotshop.com/media/files/pdf/rb-ite-12-bluetooth_hc05.pdf

[5] Atmega328P, 8-bit Microcontroller with 4/8/16/32K Bytes In-System Programmable Flash.

[Datasheet]. Available:

http://www.atmel.com/images/doc8161.pdf

[6] MPU-6050 Product Specification Revision 3.4. [Datasheet]. Available:

https://www.cdiweb.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf

[7] Brigitte Hauke, “Basic Calculation of a Boost Converter’s Power Stage”, Application report,

SLVA372C-November 2009-Revised January 2014

[8] Vgneshraja, “Program Arduino Pro Mini Using Arduino Uno” .[Online]. Available:

http://www.instructables.com/id/Program-Arduino-Pro-Mini-Using-Arduino-Uno/?ALLSTEPS

[9] MPU-6050 Accelerometer + Gyro.[Online]. Available:

http://playground.arduino.cc/Main/MPU-6050

Page 22: FINGER MOUSE

18

Appendix A Java code for the computer driver import processing.serial.*; import java.awt.*; import javax.swing.*; import java.io.*; import java.awt.event.InputEvent; Serial myPort; short portIndex = 1; int lf = 10; //ASCII linefeed String inString; //String for testing serial communication int calibrating; Robot robot = null; Point location = null; int cursor_X = 0; int cursor_Y = 0; boolean left_click = false; boolean right_click = false; int left_click_count = 0; float dt; float x_gyr; //Gyroscope data float y_gyr; float z_gyr; float x_acc; //Accelerometer data float y_acc; float z_acc; float x_fil; //Filtered data float y_fil; float z_fil; void setup() { size(1400, 800, P3D); noStroke(); colorMode(RGB, 256); String portName = "/dev/cu.usbmodem1421"; myPort = new Serial(this, portName, 9600); myPort.clear(); myPort.bufferUntil(lf); } void draw_rect_rainbow() { scale(90); beginShape(QUADS); fill(0, 1, 1); vertex(-1, 1.5, 0.25); fill(1, 1, 1); vertex( 1, 1.5, 0.25); fill(1, 0, 1); vertex( 1, -1.5, 0.25); fill(0, 0, 1); vertex(-1, -1.5, 0.25); fill(1, 1, 1); vertex( 1, 1.5, 0.25); fill(1, 1, 0); vertex( 1, 1.5, -0.25); fill(1, 0, 0); vertex( 1, -1.5, -0.25); fill(1, 0, 1); vertex( 1, -1.5, 0.25); fill(1, 1, 0); vertex( 1, 1.5, -0.25); fill(0, 1, 0); vertex(-1, 1.5, -0.25); fill(0, 0, 0); vertex(-1, -1.5, -0.25); fill(1, 0, 0); vertex( 1, -1.5, -0.25); fill(0, 1, 0); vertex(-1, 1.5, -0.25); fill(0, 1, 1); vertex(-1, 1.5, 0.25); fill(0, 0, 1); vertex(-1, -1.5, 0.25); fill(0, 0, 0); vertex(-1, -1.5, -0.25); fill(0, 1, 0); vertex(-1, 1.5, -0.25); fill(1, 1, 0); vertex( 1, 1.5, -0.25); fill(1, 1, 1); vertex( 1, 1.5, 0.25); fill(0, 1, 1); vertex(-1, 1.5, 0.25);

Page 23: FINGER MOUSE

19

fill(0, 0, 0); vertex(-1, -1.5, -0.25); fill(1, 0, 0); vertex( 1, -1.5, -0.25); fill(1, 0, 1); vertex( 1, -1.5, 0.25); fill(0, 0, 1); vertex(-1, -1.5, 0.25); endShape(); } void draw_rect(int r, int g, int b) { scale(90); beginShape(QUADS); fill(r, g, b); vertex(-1, 1.5, 0.25); vertex( 1, 1.5, 0.25); vertex( 1, -1.5, 0.25); vertex(-1, -1.5, 0.25); vertex( 1, 1.5, 0.25); vertex( 1, 1.5, -0.25); vertex( 1, -1.5, -0.25); vertex( 1, -1.5, 0.25); vertex( 1, 1.5, -0.25); vertex(-1, 1.5, -0.25); vertex(-1, -1.5, -0.25); vertex( 1, -1.5, -0.25); vertex(-1, 1.5, -0.25); vertex(-1, 1.5, 0.25); vertex(-1, -1.5, 0.25); vertex(-1, -1.5, -0.25); vertex(-1, 1.5, -0.25); vertex( 1, 1.5, -0.25); vertex( 1, 1.5, 0.25); vertex(-1, 1.5, 0.25); vertex(-1, -1.5, -0.25); vertex( 1, -1.5, -0.25); vertex( 1, -1.5, 0.25); vertex(-1, -1.5, 0.25); endShape(); } void draw() { background(0); lights(); int distance = 50; int x_rotation = 90; pushMatrix(); translate(width/6, height/2, -50); rotateX(radians(-x_gyr - x_rotation)); rotateY(radians(-y_gyr)); draw_rect(249, 250, 50); popMatrix(); pushMatrix(); translate(width/2, height/2, -50); rotateX(radians(-x_acc - x_rotation)); rotateY(radians(-y_acc)); draw_rect(56, 140, 206); popMatrix(); pushMatrix(); translate(5*width/6, height/2, -50); rotateX(radians(-x_fil - x_rotation)); rotateY(radians(-y_fil)); draw_rect(93, 175, 83); popMatrix(); textSize(24); String accStr = "(" + (int) x_acc + ", " + (int) y_acc + ")"; String gyrStr = "(" + (int) x_gyr + ", " + (int) y_gyr + ")"; String filStr = "(" + (int) x_fil + ", " + (int) y_fil + ")";

Page 24: FINGER MOUSE

20

fill(249, 250, 50); text("Gyroscope", (int) width/6.0 - 60, 25); text(gyrStr, (int) (width/6.0) - 40, 50); fill(56, 140, 206); text("Accelerometer", (int) width/2.0 - 50, 25); text(accStr, (int) (width/2.0) - 30, 50); fill(83, 175, 93); text("Combination", (int) (5.0*width/6.0) - 40, 25); text(filStr, (int) (5.0*width/6.0) - 20, 50); try{ robot = new Robot(); location = MouseInfo.getPointerInfo().getLocation(); cursor_X = (int)location.getX(); cursor_Y = (int)location.getY(); //left click if(x_acc - x_gyr > 35 && !left_click && left_click_count>30){ robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); left_click = true; left_click_count=0; } else if(x_acc - x_gyr <= 35){ left_click = false; left_click_count++; } //right click if(x_gyr - x_acc > 40 && !right_click){ robot.mousePress(InputEvent.BUTTON3_MASK); robot.mouseRelease(InputEvent.BUTTON3_MASK); right_click = true; } else if(x_gyr - x_acc <= 60) right_click = false; if((x_acc > 25 && x_gyr > 25) || (left_click && x_acc > 25) ){ cursor_Y-=5; robot.mouseMove(cursor_X,cursor_Y); left_click = false; right_click = false; } if((x_acc < -25 && x_gyr < -25) || (left_click && x_acc < -25)){ cursor_Y += 5; if(cursor_Y < 0) cursor_Y = 0; robot.mouseMove(cursor_X,cursor_Y); left_click = false; right_click = false; } if(y_acc > 25 && y_gyr > 25){ cursor_X += 5; robot.mouseMove(cursor_X,cursor_Y); left_click = false; right_click = false; } if(y_acc < -25 && y_gyr < -25){ cursor_X -= 5; if(cursor_X < 0) cursor_X = 0; robot.mouseMove(cursor_X,cursor_Y); left_click = false; right_click = false; } }catch(AWTException e){ e.printStackTrace(); } }

Page 25: FINGER MOUSE

21

void serialEvent(Serial p) { inString = (myPort.readString()); try { // Parse the data String[] dataStrings = split(inString, '#'); for (int i = 0; i < dataStrings.length; i++) { String type = dataStrings[i].substring(0, 4); String dataval = dataStrings[i].substring(4); if (type.equals("DEL:")) { dt = float(dataval); } else if (type.equals("ACC:")) { String data[] = split(dataval, ','); x_acc = float(data[0]); y_acc = float(data[1]); z_acc = float(data[2]); } else if (type.equals("GYR:")) { String data[] = split(dataval, ','); x_gyr = float(data[0]); y_gyr = float(data[1]); z_gyr= float(data[2]); } else if (type.equals("FIL:")) { String data[] = split(dataval, ','); x_fil = float(data[0]); y_fil = float(data[1]); z_fil = float(data[2]); } } } catch (Exception e) { println("Caught Exception"); } }