Ciao a tutti! Questo é il mio primo topik, volevo sapere se questo codice é corretto, perché i servo motori non si muovono più, da quando ho aggiunto 2 condizioni.
Questo é il codice:
//Importing Various Libraries
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo ServoInferiore;
Servo ServoSuperiore;
//Start Setup
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
ServoInferiore.attach (9);
ServoSuperiore.attach (10);
ServoInferiore.write(0);
ServoSuperiore.write(0);
}
//Start Loop
void loop() {
lcd.setCursor(0,0);
//Reading Analogues
int SxH = analogRead(A0); //PhotoResistor Left Up
int DxH = analogRead(A1); //PhotoResistor Right Up
int SxL = analogRead(A2); //PhotoResistor Bottom Left
int DxL = analogRead(A3); //PhotoResistor Bottom Right
int aBr; //Average Brightness of the various PhotoResistors
aBr = (SxH + DxH + SxL + DxL) / 4;
lcd.print("Luminosita': ");
lcd.print(aBr);
int Ls = SxH + SxL; //Left Side
int Rs = DxH + DxL; //Right Side
int Us = SxH + DxH; //Up Side
int Ds = SxL + DxL; //Down Side
//Conditions For The Various Rotations
if(Rs - Ls > 50)
{
If(Rs > Ls)
{
ServoInferiore.write(-15);
delay(200);
}
else if(Rs<Ls)
{
ServoInferiore.write(15);
delay(200);
}
}
else if(Us - Ds > 50)
{
if(Us>Ds)
{
ServoSuperiore.write(-15);
delay(200);
}
else if(Us <Ds)
{
ServoSuperiore.write(15);
delay(200);
}
}
}