The Arduino code was based on the code from this website:
http://mnicolato.altervista.org/arduino/ardtouch.htm
(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...
Enjoy!
// 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
println(Serial.list());
// 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:
myPort.bufferUntil('\n');
}
void draw() {
}
void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
//background(0);
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
ellipse(yPos,xPos,10,10);
//print the serial x,y data for debugging purposes only
println(inString);
}
}
}
The processing app I wrote is a derivative of the Virtual Color Mixer code found here:
http://www.arduino.cc/en/Tutorial/VirtualColorMixer
Stay tuned for more shortly....
10 comments:
Is this multitouch?
Not yet ... :-)
Thanks paul, very Good use of arduino, I will try this soon :)
Thanks again for the link
Thanks mate, let me know when you get your setup up and running :-)
Hey Paul..nice work my man. I am trying to use your project to get familiar with the Arduino..I uploaded the work but have not seen anything on the processing GUI..is the code displayed on your page enough to get it up and running ot I'm missing more code.
Thanks in advance
Hey Bassam, Thanks for the kind words. The code on the blog post is for the Processing GUI. The link in the post is a link to the code I used for the Arduino side. I did make changes to the Arduino code, however depending on your touch panel configuration, you may be able to use the code directly.
There should be everything you need between my Processing code and the link to the Arduino code. Let me know if you need more help after that...
Cheers,
-Paul
do it work with arduino UNO
hey paul awesome work there ...i'm definitely gonna try this soon...maybe with some mod's like single,double tap and drag conditions....
hey paul awesome work there ...i'm definitely gonna try this soon...maybe with some mod's like single,double tap and drag conditions....
Can it be done wireless like no connection btw your PC and arduino
Post a Comment