NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Simple Foot Mouse Buttons (Use Switches To Click Events On PC)

August 23, 2009
by Nerdful_com
Nerdful_com's Avatar

In this demonstration I will give you source code (NerdKit AVR & Visual Basic 6) and information on how to make your own mouse clicker (could be programed to do anything on PC from opening programs to running macros) for your PC. I am making this project as my hands hurt (carpal tunnel syndrome and repetitive stress injuries from 12 years of software & web programming) and I plan to use my feet to do mouse clicks (scrolling later and other features are up to you) as I find them the most painful.

First we hook up 4 push momentary on buttons or pressure switches (can be as basic as 2 wires that are spring loaded and pushed to make contact and auto releases) from PC0 to PC3 (PC0 = left click , PC1 = right click , PC2 = middle click , PC3 = double clicker).

Here's the script for the MCU:

#define F_CPU 14745600
#include <avr/io.h>
#include <avr/iom168.h>
#include <avr/pgmspace.h>
#include "../libnerdkits/delay.h"
#include "../libnerdkits/uart.h"
/* 
Made by www.Nerdful.com
This is the atmega program for 2 button mouse (right left clicks).
This will write to PC and PC responds with mouse clicks.
The PC needs a interface that reads the 1 or 0 and return a click.
This code came with a Visual Basic project for PC interface.
*/
int main(void) {
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout = &uart_stream;
DDRC&=~_BV(0);//set PORTD button0 to zero as input
PORTC|=_BV(0);//Enable pull up
//PORTB|=_BV(1);//PB1 led OFF
//DDRB|=_BV(1);//set LED PB1 pin1 to one as output
DDRC&=~_BV(1);//set PC1 button1 to zero as input
PORTC|=_BV(1);//Enable pull up
DDRC&=~_BV(2);PORTC|=_BV(2);DDRC&=~_BV(3);PORTC|=_BV(3);DDRC&=~_BV(4);PORTC|=_BV(4);
while(1) {
if (bit_is_clear(PINC, 0)){//if button is pressed
//PORTC&=~_BV(1);//LED ON
loop_until_bit_is_set(PINC, 0);//ON while Button 1 is pressed
//PORTC|=_BV(1);// LED OFF
printf_P(PSTR("0"));delay_ms(100);
}
if (bit_is_clear(PINC, 1)){
loop_until_bit_is_set(PINC, 1); //button 2
printf_P(PSTR("1"));delay_ms(100);
}
if (bit_is_clear(PINC, 2)){
loop_until_bit_is_set(PINC, 2); //button 3
printf_P(PSTR("2"));delay_ms(100);
}
if (bit_is_clear(PINC, 3)){
loop_until_bit_is_set(PINC, 3);
printf_P(PSTR("3"));delay_ms(100); //button 4
}
}
}

For the VB software (program that watches for serial port calls and responds accordingly), you will need to add component Microsoft Comm Control and you will need to add module MouseCommands.bas to your project.

This VB code can be easily made to run macros, VBscripts, DOS prompt commands, open programs, send keystrokes, go to a web page, send queries to other devices and so many other ways your computer can interact!

Here is the VB6 source code:

Private Sub Form_Load()
MSComm1.CommPort = 5 'You may have to change to suit your port#
MSComm1.Settings = "115200,N,8,1"
MSComm1.InputMode = 1
MSComm1.RThreshold = 1 'length of input accepted
MSComm1.PortOpen = True
End Sub
Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim Arr() As Byte
Dim I As Integer
Dim textz As String
Select Case MSComm1.CommEvent
Case comEvReceive
Do While MSComm1.InBufferCount > 0
buffer = buffer & MSComm1.Input
Arr = buffer
For I = LBound(Arr) To UBound(Arr)
textz = nerdful(Hex$(Arr(I))) 'Arr(I)
If InStr(textz, "0") Then
MSButton = "Left" 'right mouse click ready
MouseClick 'mouse clicker go!
End If
If InStr(textz, "1") Then
MSButton = "Right" 'right mouse click ready
MouseClick 'mouse clicker go!
End If
If InStr(textz, "2") Then
MSButton = "Middle" 'Middle mouse click ready
MouseClick 'mouse clicker go!
End If
If InStr(textz, "3") Then
MSButton = "Double Click" 'DOUBLE mouse click ready
MouseClick 'mouse clicker go!
End If
Next
Loop
End Select
End Sub
Public Function nerdful(ByVal HexToStr As String) As String
Dim strTemp As String
Dim strReturn As String
Dim I As Long
For I = 1 To Len(HexToStr) Step 3
strTemp = Chr$(Val("&H" & Mid$(HexToStr, I, 2)))
strReturn = strReturn & strTemp
Next I
nerdful = strReturn
End Function

By www.Nerdful.com

August 23, 2009
by Nerdful_com
Nerdful_com's Avatar

Basically I am making input devices for handicapped & disabled people (or those concerned about RS).

FooTime is a product I own (my wife paid 150 dollars for it but here we can eventually make it for much less) and so far I have basically maade (above codes) a 4 button version without a mouse you move around (I find this bothers my knees anyhow). Even USB pedals and big button switches are like $50 and up (you only get one or two buttons).

FooTime webpage: www.bilila.com/foot_mouse_slipper_mouse

DETIALS: In addition to its wide applications in ergonomics, rehab, assistive technology, clean room (lab), dirty room (car repair), cyber room (video game), etc, Footime foot mouse is also a very powerful input device for audio/video editor, animator, graphic designer, architect, composer, arranger, product designer (CAD, etc), CT scanner, software programmer or any intensive computer user.

August 23, 2009
by Nerdful_com
Nerdful_com's Avatar

HERE is one of the first videos of the 2 button demo version (before I made it 4 buttons). I will be adding more buttons, a scroll wheel and other feautres in the future.

You will notice that the 2 switches are just cheap disposable paperclips that are pushed to make contact (spring loaded button effect, I do not have enough real buttons yet) on a Canadian copper penny that goes to ground (GND). In the video we have 2 homemade buttons, left paperclip goes to PC0 and the right one goes to PC1 on the MCU.

Post a Reply

Please log in to post a reply.

Did you know that you can build a circuit to convert the "dit" and "dah" of Morse code back into letters automatically? Learn more...