#include <Servo.h>
/*#include <LiquidCrystal_I2C.h>
#include <Wire.h>
//#include <LCD.h>*/
Servo Motor;
Servo Motor2;
//LiquidCrystal_I2C LCD (0x27, 2,1,0,4,5,6,7);
int S1;
int VER;
int HOR;
int POSV;
int POSH;
int MIN = 500;
int MAX = 2400;
int PWM1 = 5;
int PWM2 = 6;
void setup() {
pinMode (2, INPUT_PULLUP);
Motor.attach(PWM1, MIN, MAX);
Motor2.attach(PWM2, MIN, MAX);
Serial.begin(9600);
/* LCD.setBacklightPin (3, POSITIVE);
LCD.setBacklight(HIGH);
LCD.begin (16,2);
LCD.clear ();*/
}
void loop() {
VER= analogRead(A0);
HOR= analogRead(A1);
S1 = digitalRead (2);
/*Motor.write (0);
delay(1000);
Motor.write (90);
delay(1000);
Motor.write (180);
delay(1000);*/
Serial.print ("VERTICAL: ");
Serial.print (VER);
/*LCD.setCursor(0, 0);
LCD.print ("VERTICAL: ");
LCD.print (VER);*/
POSV = map (VER, 0, 1023, 180, 0);
Motor.write(POSV);
/*LCD.setCursor(1, 0);
LCD.print ("HORIZONTAL: ");
LCD.print (HOR);*/
Serial.print (" HORIZONTAL: ");
Serial.print (HOR);
POSH = map (HOR, 0, 1023, 0, 180);
Motor2.write(POSH);
Serial.print (" PULSADOR: ");
Serial.println (S1);
}