Hey I am working on a smart solar panel that consist of 5 photocells placed at different angles then the input is interpreted by an Arduino and it tells a servo motor to what angle to move the solar panel. the only problem that I that I have is that the motor doesn't change position. I think it might have something to do with the code but I cannot find the problem, help is highly appreciated. Here is my code:
#include <Servo.h>
Servo myservo;
int photocell1 = 1;
int photocell2 = 2;
int photocell3 = 3;
int photocell4 = 4;
int photocell5 = 5;
int photocell1Reading;
int photocell2Reading;
int photocell3Reading;
int photocell4Reading;
int photocell5Reading;
void setup(void) {
myservo.attach(9);
}
void loop(void) {
photocell1Reading = analogRead(photocell1);
photocell2Reading = analogRead(photocell2);
photocell3Reading = analogRead(photocell3);
photocell4Reading = analogRead(photocell4);
photocell5Reading = analogRead(photocell5);
// Far left photocell
if(photocell1Reading > photocell2Reading, photocell3Reading, photocell4Reading, photocell5Reading){
myservo.write(25);
}
// 45 left photocell
else if(photocell2Reading > photocell1Reading, photocell3Reading, photocell4Reading, photocell5Reading){
myservo.write(45);
}
// Center photocell
else if(photocell3Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell5Reading){
myservo.write(90);
}
// 45 right photocell
else if(photocell4Reading > photocell1Reading, photocell2Reading, photocell3Reading, photocell5Reading){
myservo.write(135);
}
// Far left photocell
else(photocell5Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell3Reading);{
myservo.write(175);
}
}[/font]