Skip to content

Commit 7e49390

Browse files
committed
Arduino Linetracer
Signed-off-by: vesselofgod <[email protected]>
1 parent a333759 commit 7e49390

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

final.ino

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <Servo.h>
2+
3+
int servoPin=10;
4+
int Rightpin = 6;
5+
int Leftpin = 9;
6+
Servo servo;
7+
int angle=70;
8+
9+
void setup() {
10+
Serial.begin(9600);
11+
pinMode(4,OUTPUT);
12+
pinMode(5,OUTPUT);
13+
pinMode(servoPin,OUTPUT);
14+
pinMode(Rightpin, INPUT);
15+
pinMode(Leftpin, INPUT);
16+
servo.attach(servoPin);
17+
18+
}
19+
20+
void loop() {
21+
int Rightdata;
22+
int Leftdata;
23+
Rightdata = digitalRead(Rightpin);
24+
Leftdata = digitalRead(Leftpin);
25+
if(Rightdata==HIGH && Leftdata==HIGH) //black=HIGH white=LOW
26+
{
27+
analogWrite(5,255);
28+
digitalWrite(4,LOW);
29+
servo.write(70);//기준각=70
30+
}
31+
else if(Rightdata==LOW && Leftdata==HIGH)
32+
{
33+
analogWrite(5,200);
34+
digitalWrite(4,LOW);
35+
servo.write(40);//Left turn
36+
}
37+
else if(Rightdata==HIGH && Leftdata==LOW)
38+
{
39+
analogWrite(5,200);
40+
digitalWrite(4,LOW);
41+
servo.write(100);//Right turn
42+
}
43+
else
44+
{
45+
analogWrite(5,255);
46+
digitalWrite(4,LOW);
47+
}
48+
49+
}

0 commit comments

Comments
 (0)