Created
March 4, 2020 16:41
-
-
Save sholok404/2d123beb98b3cb3f30a71c393a7e9d76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo panel; | |
int pos = 0; | |
int leftLDR = A1; | |
int rightLDR = A0; | |
int error_threshold = 50; | |
void setup() { | |
panel.attach(9); | |
Serial.begin(9600); | |
pinMode(leftLDR, INPUT); | |
pinMode(rightLDR, INPUT); | |
} | |
void loop() { | |
int leftLDRval = analogRead(leftLDR); | |
int rightLDRval = analogRead(rightLDR); | |
delay(1000); | |
if (leftLDRval > rightLDRval) { | |
Serial.println("Left LDR"); | |
Serial.println(leftLDRval); | |
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
panel.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} | |
else if (rightLDRval > leftLDRval) { | |
Serial.println("Right LDR"); | |
Serial.println(rightLDRval); | |
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees | |
panel.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} | |
else { | |
Serial.println("Left LDR = Right LDR"); | |
Serial.println("Left LDR"); | |
Serial.println(leftLDRval); | |
Serial.println("Right LDR"); | |
Serial.println(rightLDRval); | |
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
panel.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment