forked from xzlovier/Robodive-Project-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdino.cpp
47 lines (43 loc) · 1.02 KB
/
dino.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <Servo.h>
const int LDR1 = A0;
const int LDR2 = A1;
const int servoPin = 9 ;
Servo myServo;
void setup(){
pinMode(LDR1, INPUT);
pinMode(LDR2, INPUT);
myServo.attach(servoPin);
myServo.write(0);
Serial.begin(9600);
}
void loop() {
int BG_brightness = analogRead(LDR2);
int Object = analogRead(LDR1);
Serial.println("Object Value: ");
Serial.println(Object);
Serial.println("Background Value: ");
Serial.println(BG_brightness);
if (BG_brightness >= 750) {
if (Object < 700){
myServo.write(90);
delay(100);
myServo.write(0);
delay(200);
}
else{
Serial.println("Stable");
}
}
else {
if (Object < 470 ){
myServo.write(90);
delay(100);
myServo.write(0);
delay(200);
}
else{
Serial.println("Stable");
}
}
//delay(1000);
}