Etch a Sketch coding help
in
Programming Questions
•
1 year ago
I have this code i am using that allows me to draw lines with two rotary resistors. the only problem is its drawing is dots instead of lines. i am making a very simple (what im finding difficult) etch a sketch that will soon turn into a complex project using a verity of other components but for now i am trying to tweak this code to make it draw better. here is my code i am currently using any help is much appreciated.
BTW i am very new to Processing and layman's terms would be best to help.
import processing.serial.*;
float xPos = 0;
float yPos = 0;
Serial port;
void setup()
{
size(800, 600);
println(Serial.list());
port = new Serial(this, Serial.list()[1], 9600);
port.bufferUntil('\n');
smooth();
noStroke();
background(255);
}
void draw()
{
fill(0);
ellipse(xPos, yPos, 5, 5);
}
void serialEvent(Serial port)
{
String inString = port.readStringUntil('\n');
inString = trim(inString);
if (inString != null)
{
inString = trim(inString);
float[] pos = float(split(inString, ","));
for (int posNum = 0; posNum < pos.length; posNum++) { print("Sensor " + posNum + ": " + pos[posNum] + "\t"); } println(); if (pos.length >=2)
{
xPos = map(pos[0], 0, 1023, 0, width);
yPos = map(pos[1], 0, 1023, 0, height);
}
}
port.write("A");
}
1