Beginner's Question: "unexpected token: int"
in
Programming Questions
•
3 years ago
On the following code, I get the error message "unexpected token: int".
I am just starting out trying to learn programming through Processing and have been working through some textbook exercises. I was expecting to connect to a microcontroller and control a servo motor, but don't exactly know how to fix this problem.
Any help would be great.
Serial port;
float mx = 0.0;
void setup(){
size(200, 200);
noStroke();
frameRate(10);
port = new Serial(this, 9600);
}
void draw(){
background(0);
fill(204);
rect(40, height/2 - 15, 120, 25);
float dif = mouseX - mx;
if(abs(dif) > 1.0){
mx += dif/4.0;
}
mx = constrain(mx, 50, 149);
noStroke();
fill(255);
rect(50, (height/2) - 5, 100, 5);
fill(204, 102, 0);
rect(mx - 2, height/2 - 5, 4, 5);
int angle = int(map(mx, 50, 149, 0, 180));
port.write(angle);
}
1
