If I declare a variable in void setup() and try to do something with it in void loop(), it just says that the variable is undeclared. Here is the code:
#include "Servo.h"
void setup() {
Servo servo1;
int x_key = A0;
servo1.attach(2);
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
int x_position = 90;
}
void loop() {
if (analogRead(A0) < 512) {
x_position++;
servo1.write(x_position);
}
}
{}(code formatting) button. I did it for you.