etch-a-sketch with arduino

i've found a piece of code which allows the positions of 2 potentiometers connected to an arduino to be displayed as a virtual etch-a-sketch

however, the lines eventually dissappear. the code is as follows:

// Etch-a-Sketch
// by Trevor Shannon
//
// based on Graph
// by David A. Mellis

import processing.serial.*;

Serial port;
String buff = "";
String buff1 = "";
String buff2 = "";
int index = 0;
int NEWLINE = 10;

// Store the last 256 values received so we can graph them.
int[] valuesx = new int[256];
int[] valuesy = new int[256];

void setup()
{
size(512, 512);

port = new Serial(this, "COM9", 9600);

// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);

}

void draw()
{
background(0);
stroke(0);

// Graph the stored values by drawing a lines between them.
for (int i = 0; i < 255; i++){
stroke(i);
line(512 - valuesx_, 512 - valuesy*, 512-valuesx[i + 1], 512 - valuesy[i + 1]);_
_
}_
_
while (port.available() > 0)_
_
serialEvent(port.read());_
_
}_
void serialEvent(int serial)
_
{_
_
if (serial != NEWLINE) {_
_
// Store all the characters on the line._
_
buff += char(serial);_
_
}_
_
else {_
_
// The end of each line is marked by two characters, a carriage*_
* // return and a newline. We're here because we've gotten a newline,*
* // but we still need to strip off the carriage return.*
* buff = buff.substring(0, buff.length()-1);*
* index = buff.indexOf(",");*
* buff1 = buff.substring(0, index);*
* buff2 = buff.substring(index+1, buff.length());*

* // Parse the String into an integer. We divide by 4 because*
* // analog inputs go from 0 to 1023 while colors in Processing*
* // only go from 0 to 255.*
* int x = Integer.parseInt(buff1)/2;*
* int y = Integer.parseInt(buff2)/2;*
* // Clear the value of "buff"*
* buff = "";*

* // Shift over the existing values to make room for the new one.*
* for (int i = 0; i < 255; i++)*
* {*
_ valuesx = valuesx[i + 1];
valuesy = valuesy[i + 1];
* }*_

* // Add the received value to the array.*
* valuesx[255] = x;*
* valuesy[255] = y;*
* }*
}[/quote]
if any1 knows how to fix this, will be very greatfull....thnx

You only store 256 lines in this sketch, in places like:-
int[] valuesx = new int[256];
int[] valuesy = new int[256];
and
for (int i = 0; i < 255; i++)
plus some other places

If you change the value to a bigger number you can store more lines before they start to be replaced by new lines in the wrap round.

This is not actually a hardware interfacing problem, in fact it is not even an Arduino problem, it's a Processing software problem.

thanx a lot for that m8...ye i'll jus change it it higher values

It's an etch-a-sketch, the lines are supposed to eventually disappear.

(I've been waiting till after you got a constructive answer) ;D

It's an etch-a-sketch, the lines are supposed to eventually disappear.

Yes but only when you turn it upside down and shake it.
So you could add an accelerometer to detect that. :stuck_out_tongue:

Yes but only when you turn it upside down and shake it.
So you could add an accelerometer to detect that

Thats funny until you think "wait you could actually do that"

ye im gona attach a tilt sensor so that when it is shaken, the lines will then dissappear....but thanx neways guys

here's my version of a digital etch-a-sketch.

http://kenfrederick.blogspot.com/2009/05/arduino-digi-sketch.html

it's has a shake to clear funtion using apple's built in SMS and if you stick at it long enough it will draw a picture. i used arrayList to store the variables so no matter how long you mess with it the lines stay on the screen.

then i refined it a little bit, using a voltage regulator to smooth out the jitter.

http://kenfrederick.blogspot.com/2009/05/arduino-digi-sketch-update.html

Ken