I'm sure this gets posted a lot because it's a pretty common error- but I really can't find where the semicolon is meant to go. The line that gets selected is
for (analogRead(Y_pin), Y_pin < 100, increment++) {
but I don't spot anything. Here's my full code:
#include <Servo.h>
Servo myservo;
Servo myservo2;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
int increment = 0;
void setup() {
myservo.attach(3);
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200); //USE 115200 BAUD
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
for (analogRead(Y_pin), Y_pin < 100, increment++) {
myservo.write(increment);
delay(1);
}
delay(500);
}
for(statement run at start of loop; test run before each iteration - loop will terminate if this is false at the start of each iteration; statement run after each iteration) { code to execute during loop }
Basically everything about that line makes no sense...
you have commas instead of semicolons
The initial statement takes an analogRead() on Y_pin and throws away the result. Why?
You then test if Y_pin is less than 100. You have declared it to be a constant with value of 1, so this test will always be true and the loop will run forever.
Thus, if you corrected the syntax, the code would sit there looping forever, while increment would increase from 0 to 32767, then overflow and wrap around to -32768, and these (clearly wrong) values will be written to the servo.
I have no idea what you were trying to do there, but I'm pretty sure that's not it.
Not sure your intent here but a write to the servo should between 0-180 so you need to make sure you limit that. Are you trying to use an analog for feedback as to the position of whatever the servo is moving?
for (analogRead(Y_pin), Y_pin < 100, increment++)
{
myservo.write(increment);
delay(1);
}