Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/*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("
"); }; void svgFooter(){ Serial.println ("
"); };
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)