#include <Servo.h>
Servo tilt, pan;
// Arduino pin numbers
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 x, y;
// Second joystick pin numbers
const int SW_pinn = 4;
const int X_pinn = 3;
const int Y_pinn = 5;
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200); // setting serial baud rate tp 115200
tilt.attach(7);
}
void loop() {
x = X_pin; // defining the variable
y = Y_pin;
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");
x = map(analogRead(X_pin), 0, 1023, 900, 2100); // scale it to use with the servo b/w 900 usec to 2100 usec
y = map(analogRead(Y_pin), 0, 1023, 900, 2100);
tilt.write(x); // sets the servo position according to the scaled value
pan.write(y);
delay(5);
}
x = X_pinn; // defining the variable
y = Y_pinn;
Serial.print("X-axis: ");
Serial.print(analogRead(X_pinn));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pinn));
Serial.print("\n\n");
x = map(analogRead(X_pinn), 0, 1023, 900, 2100); // scale it to use with the servo b/w 900 usec to 2100 usec
y = map(analogRead(Y_pinn), 0, 1023, 900, 2100);
tilt.write(x); // sets the servo position according to the scaled value
pan.write(y);
delay(5);
}
When I compile this code in the Arduino IDE it gives me the error
arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/166416428 -hardware arduino-builder/hardware -hardware arduino-builder/packages/cores -tools arduino-builder/tools -tools arduino-builder/packages/tools -built-in-libraries arduino-builder/latest -libraries /tmp/358566849/pinned -libraries /tmp/358566849/custom -fqbn arduino:avr:uno -build-cache /tmp -verbose=false /tmp/358566849/sketch_may12a
Multiple libraries were found for "Servo.h"
Used: /home/admin/builder/arduino-builder/latest/Servo-1.1.2
Not used: /home/admin/builder/arduino-builder/latest/Printoo_Library-1.0.2
/tmp/358566849/sketch_may12a/sketch_may12a.ino:40:3: error: 'x' does not name a type
x = X_pinn; // defining the variable
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:41:3: error: 'y' does not name a type
y = Y_pinn;
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:42:3: error: 'Serial' does not name a type
Serial.print("X-axis: ");
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:43:3: error: 'Serial' does not name a type
Serial.print(analogRead(X_pinn));
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:44:3: error: 'Serial' does not name a type
Serial.print("\n");
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:45:3: error: 'Serial' does not name a type
Serial.print("Y-axis: ");
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:46:3: error: 'Serial' does not name a type
Serial.println(analogRead(Y_pinn));
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:47:3: error: 'Serial' does not name a type
Serial.print("\n\n");
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:48:3: error: 'x' does not name a type
x = map(analogRead(X_pinn), 0, 1023, 900, 2100); // scale it to use with the servo b/w 900 usec to 2100 usec
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:49:3: error: 'y' does not name a type
y = map(analogRead(Y_pinn), 0, 1023, 900, 2100);
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:50:3: error: 'tilt' does not name a type
tilt.write(x); // sets the servo position according to the scaled value
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:51:3: error: 'pan' does not name a type
pan.write(y);
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:52:8: error: expected constructor, destructor, or type conversion before '(' token
delay(5);
^
/tmp/358566849/sketch_may12a/sketch_may12a.ino:53:1: error: expected declaration before '}' token
}
^
exit status 1
In short, it saying that x does not name a type in this part of the code
x = X_pinn; // defining the variable
y = Y_pinn;
Serial.print("X-axis: ");
Serial.print(analogRead(X_pinn));
Even though I defined it as a variable at the beginning... Any ideas?