Things used in this project

Hardware components:
2-Axis Joystick
×1
12002 04
Breadboard (generic)
×1
Push Buttons
×2
Wire
×1
Pinoccio Scout
×1

Code

IMG_1052.JPGJavaScript
var Pinoccio = require("pinoccio-io");
var five = require('johnny-five');

// NodObjC Bridge to call Objective C Commands to control Mac Mouse Cursor
var $ = require('NodObjC');
// To  Move the Mouse We need the Cocoa Objective C Framework
$.framework('Cocoa');
var pool = $.NSAutoreleasePool('alloc')('init');
IMG_1053.JPGJavaScript
// Create The Pinoccio Board   
var board = new five.Board({
    io: new Pinoccio({
        token: '{{Your Pinoccio API Token}}',
        troop: '{{Your Pinoccio Troop Number}}',
        scout: '{{Pinoccio Scout Number}}'
    }).on('error', function(err) {
        console.log('error> ', err);
    })
});

// Create the point Variables
var ptX = 500;
var ptY = 500;

// Speed of the Mouse Cursor
var speed = 20;
IMG_1052.JPGJavaScript
// Initialize The Board 
board.on('ready', function() {
    console.log("ready");

    // Initialize the Push Buttons
    var leftClick = new five.Button({
        pin: "D3",
        invert: true
    });
    var rightClick = new five.Button({
        pin: "D2",
        invert: true
    });

    // Initialize the Joystick
    joystick = new five.Joystick({
        pins: ["A0", "A1"],
        freq: 50
    });
    // Inject the Joystick to the Board
    board.repl.inject({
        joystick: joystick
    });

    // Joystick Event API
    joystick.on("axismove", function(err, timestamp) {
        if (this.fixed.x < 0.85 && ptX > 0) {
            ptX -= speed * (1 - this.fixed.x);
        } else if (this.fixed.x > 0.97 && ptX < 1480) {
            ptX += speed * this.fixed.x;
        }
        if (this.fixed.y < 0.85 && ptY < 880) {
            ptY += speed * (1 - this.fixed.y);
        } else if (this.fixed.y > 0.97 && ptY > 0) {
            ptY -= speed * this.fixed.y;
        }

        // Log the X and Y coordinates of the Mouse, along with the Joystick Values
        console.log("LR:", this.fixed.x, "X: ", ptX);
        console.log("UD:", this.fixed.y, "Y: ", ptY);

        // Move the Mouse
        var moveEvent = $.CGEventCreateMouseEvent(null, $.kCGEventMouseMoved, $.CGPointMake(ptX, ptY), $.kCGMouseButtonLeft);
        $.CGEventPost($.kCGHIDEventTap, moveEvent);
    });

    // Detect if Left Push Button is Pressed
    leftClick.on("down", function() {
        var clickDown = $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseDown, $.CGPointMake(ptX, ptY), $.kCGMouseButtonLeft);
        $.CGEventPost($.kCGHIDEventTap, clickDown);
        var clickUp = $.CGEventCreateMouseEvent(null, $.kCGEventLeftMouseUp, $.CGPointMake(ptX, ptY), $.kCGMouseButtonLeft);
        $.CGEventPost($.kCGHIDEventTap, clickUp);
    });

    //Detect if Right Push is Pressed
    rightClick.on("down", function() {
        var clickDown = $.CGEventCreateMouseEvent(null, $.kCGEventRightMouseDown, $.CGPointMake(ptX, ptY), $.kCGEventRightMouseDown);
        $.CGEventPost($.kCGHIDEventTap, clickDown);
        var clickUp = $.CGEventCreateMouseEvent(null, $.kCGEventRightMouseUp, $.CGPointMake(ptX, ptY), $.kCGEventRightMouseDown);
        $.CGEventPost($.kCGHIDEventTap, clickUp);
    });
});

pool('drain');

Credits

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

DHT22 Sensor and Pinoccio
  • 1,586
  • 5

Full instructions

Using DHT22 Temperature and Humidity sensor with Pinoccio

Mesh Your Brain
  • 3,344
  • 21

Full instructions

Build your own Internet of Brains with this wireless EEG hack!

Human Presence Detection & Visualization
  • 1,048
  • 8

Full instructions

Team Cogitate's social radar displays people nearby as a set of glowing orbs

Data Painting
  • 1,548
  • 11

Full instructions

Create ephemeral, data-rich light paintings in the air, using a motion sensor.

Data Painting

Jake Ingman

Hideous Arc Reactor Sweater (WIP)
  • 774
  • 6

Work in progress

Power through the holiday slump with this festive, EEG-reactive sweater!

Solar Powered Pinoccio Scout
  • 1,044
  • 9

Run your wireless mesh forever with Adafruit's solar LiPo charger

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback