Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #define echoPin 7 // Echo Pin
- #define trigPin 8 // Trigger Pin
- #define Pizo 12 //The Pizo
- Servo ServoRight;
- Servo ServoLeft;
- int xVal ;
- int yVal;
- int servoRight;
- int servoLeft;
- int maximumRange = 300;
- int minimumRange = 10;
- long duration, distance;
- const int light = 5;
- const int light1 = 6;
- boolean x = true;
- void setup() {
- Serial.begin(9600);
- ServoRight.attach(6);
- ServoLeft.attach(5);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- pinMode(Pizo, OUTPUT);
- pinMode(light , OUTPUT);
- pinMode(light1 , OUTPUT);
- }
- void loop(){
- xVal = analogRead(A0);
- yVal = analogRead(A1);
- Serial.print("X= ");
- Serial.println (xVal);
- Serial.print("Y= ");
- Serial.println(yVal);
- if (yVal < 400)
- {
- ServoRight.write(180);
- ServoLeft.write(0);
- }
- else if (yVal > 600)
- {
- ServoRight.write(0);
- ServoLeft.write(180);
- }
- else if (xVal < 400)
- {
- ServoRight.write(180);
- ServoLeft.write(180);
- digitalWrite(13, HIGH);
- }
- else if (xVal > 600)
- {
- ServoRight.write(0);
- ServoLeft.write(0);
- digitalWrite(12, HIGH);
- }
- else (yVal, xVal = 509, 510, 511, 512, 513);
- {
- ServoRight.write(90);
- ServoLeft.write(90);
- }
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration/58.2;
- if (distance >= maximumRange || distance <= minimumRange) {
- Serial.println("Good thing yall aint testing me today would've ran your a** over");
- } else {
- Serial.println("BOY IF YOU DONT MOVE IM FINNA RUN YOU OVER STOOOOOOOOPED");
- Serial.print(distance);
- Serial.println(" cm");
- }
- int thisPitch = map(distance, 0, 200, 2093, 22);
- tone(4, thisPitch);
- delay(500);
- noTone(4);
- delay(10);
- int c = analogRead(A2);
- delay(500);
- if ( c<300 && x == true){
- digitalWrite(5, HIGH);
- x = false;
- digitalWrite(6, HIGH);
- x = false;
- delay(1000);
- }
- else if ( c <300 && x == false){
- x = true;
- digitalWrite(5,LOW);
- digitalWrite(6,LOW);
- delay(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement