Click the link below and....Get Sparked!

Sunday, August 2, 2009

Arduino TouchScreen Test 1

This is a simple test of a 4-Wire resistive touchscreen connected to an Arduino MEGA running a simple Paint application that I wrote in Processing.

The Arduino code was based on the code from this website:

(The website will need translation, however, the video and code are there)

Below is the Processing code for the Arduino Touch Screen Paint application I wrote for the above video...


// Touch Screen Paint v1.1

// This example takes in a serial string of comma-separated values
// from a 4-Wire Resistive touch screen (0 to 1023), maps them to the range
// 0 to 480 or 0 to 800 of x,y values, and uses them to draw a line on the screen.

// By
// Paul D'Intino

import processing.serial.*;

float xPos = 0; // touch screen x value
float yPos = 0; // touch screen y value

Serial myPort;

void setup() {
size(800, 480); //define the size of the Paint window
background(0); //set the background to black
// List all the available serial ports
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[2], 9600);
// don't generate a serialEvent() unless you get a new line character:

void draw() {


void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split the string on the commas and convert the
// resulting substrings into an integer array:
float[] sensor = float(split(inString, ","));
// if the array has at least three elements, you know
// you got the whole thing. Put the numbers in the
// color variables:
if (sensor.length >=2) {
// map them to the range 0-255:
xPos = map(sensor[0], 0, 1023, 0, 480);
yPos = map(sensor[1], 0, 1023, 0, 800);
//define the stroke and fill color of the circle
stroke(0,255,0); //green (R,G,B)
fill(0,255,0); //green (R,G,B)
//draw the circle at the touch screen sensor x and y position
//print the serial x,y data for debugging purposes only

The processing app I wrote is a derivative of the Virtual Color Mixer code found here:

Stay tuned for more shortly....