Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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 ("<polyline points=\""); //x,y points go here
- }
- void polyLineEnd(){
- Serial.println ("0, 0\" stroke=\"red\" fill=\"transparent\" stroke-width=\"5\"/>"); //a dirty hack to avoid dealing with 1 last trailing comma.
- }
- void svgHeader(){
- Serial.println("<svg width=\"1023\" height=\"1023\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">");
- };
- void svgFooter(){
- Serial.println ("</svg>");
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement