Obi-Wan the Cursor

I use four screens, and sometimes lose my cursor. No more! I have Obi-WanQui-Gon to point the way for me. Using the Makezine Controller, a small X program, OSC, and a pair of servo motors, I have a real-life cursor (2.4MB video).

The X program (included below) tracks the cursor, and ten times a second, sends an OSC (Open Sound Control) command using sendOSC to the controller. The commands work together like this:

~/src/servo | osc/sendOSC/sendOSC -h 10000

/* compile with this command:
cc servo.c -o servo -L/usr/X11R6/lib -lX11
#include <stdio.h>
#include <X11/Xlib.h>

main(int argc, char *argv[])
    Display *dpy = XOpenDisplay(NULL);
    Window thiswindow;
    Window root, child;
    XEvent ev;
    int x, y, oldx, oldy;
    int junk;
    unsigned int state;

    thiswindow = DefaultRootWindow(dpy);
    for(;;) {
        XQueryPointer(dpy, thiswindow, &root, &child, &x,&y, &junk,&junk, &state);
        if (oldx != x || oldy != y) {
            printf("/servo/0/position %d\n/servo/1/position %d\n", x / 3, y * 1024 / 768);
            oldx = x;
            oldy = y;
        usleep(1000L * 1000L / 10);

Digg this!

Russ Nelson
Last modified: Mon Oct 9 22:37:08 EDT 2006