/*EtchaSketch
* 2 pots, X,Y, increment, and plot lines. might require error checks, and corrections
* increment accordingly
*
* This program communicates on the serial port, to a seprate program that handles the drawing of recieved cordinates.
*
*/
/**Fucntion Defs**/
void svgHeader();
void svgFooter();
void polyLineBegin();
void polyLineEnd();
int Reset = 4; //programticaly reset the arduino
int potX = A0;
int potY = A1;
int sensorValX = 0;
int sensorValY = 0;
int oldX = 0;
int oldY = 0;
int del = 2; //a button on pin 2 for deleting drawn content
int delbutton = 0;
void setup() {
Serial.begin(9600);
pinMode(del, INPUT);
delay(1000);
}
void loop() {
// close the svg and start over
if(digitalRead(del) == LOW ){
delbutton=1;
polyLineEnd();
svgFooter();
digitalWrite(Reset, LOW);
digitalWrite(Reset, HIGH);
svgHeader();
polyLineBegin();
}else{
delbutton=0;
}
sensorValX = analogRead(potX);
sensorValY = analogRead(potY);
/*dont draw if pots not changing
Ah but the sensors are noisy, so thresholding
*/
int threshold =3;
int xVariance = abs(sensorValX-oldX);
int yVariance = abs(sensorValY-oldY);
if (xVariance >=threshold && yVariance >= threshold ||xVariance >=threshold || yVariance >=threshold){
Serial.print(sensorValX);
Serial.print(",");
Serial.print(sensorValY);
Serial.print(",");
delay(100);
oldX=sensorValX;
oldY=sensorValY;
}else{
; //dont do shi.
}
} //end loop
/**Functions**/
void polyLineBegin(){
Serial.println (""); //a dirty hack to avoid dealing with 1 last trailing comma.
}
void svgHeader(){
Serial.println("");
};