Snowpad‎ > ‎2. Examples‎ > ‎

touchpad_example: multi-touch trackpad example

This example illustrates how to transform the Snowpad into a multi-touch trackpad.

Required Hardware

  • Snowpad
  • Microcontroller - In this example, it is assumed that the reader connect Arduino Micro or Snowboard. However, the reader can easily apply information here to his/her microcontroller.

Connection

Connect a microcontrolller to Snowpad. Arduino Micro can be directly connected via on-board socket. Snowboard or other microcontroller is connected via the external I2C port of Snowpad.

Upload Firmware (Arduino Micro and Snowboard)

1. Run Arduino IDE

2. In Tools-Board, choose Arduino Micro or Arduino Leonardo if you are using Snowboard.

3. In Tools-Port, choose an appropriate port to which your Arduino Micro or Snowboard is attached.

4. Go to File-Examples-Snowboard and choose touchpad_example to open the example.

5. Switch to the example touchpad_example.
1) If you are using Arduino Micro, uncommnet line 16 and comment out line 17.
2) If you are using Snowboard, comment out line 16 and uncomment line 17.
3) Click upload button.

Multi-touch Trackpad

After upload, Snowpad is ready to work as a multi-touch trackpad. The firmware defines the coordinate as shown below. Upper 2/3 area is assigned as a touch gesture area while the lower part is for left button area.
  • You can apply two-finger pinch gesture in the touch area.

Arduino Code


/*
 touchpad_example.ino
 Copyright (c) 2014 Kitronyx http://www.kitronyx.com
 GPL V3.0
*/

#include <Wire.h>
#include <Snowpad.h>
#include "touchpad.h"

unsigned char touchid;
unsigned char pen;
unsigned int touchx;
unsigned int touchy;

Snowpad snowpad(HOST_SNOWPAD_V1R3); // Arduino Micro
// Snowpad snowpad(HOST_SNOWBOARD); // SNOWBOARD
TouchPad touchpad;

void setup()
{
    touchpad.setLandscape();
    Wire.begin();
    Serial.begin(115200);
    snowpad.begin();
}

void loop()
{
    if (snowpad.read())
    {
        touchid = snowpad.getTouchID();
        pen = snowpad.getPen();
        touchx = snowpad.getTouchX();
        touchy = snowpad.getTouchY();
        
        touchpad.evaluate(touchid, pen, touchx, touchy);   
    }
}