NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// Sabitler
#define MotorL1 6
#define MotorL2 9
#define MotorLE 5
#define MotorR1 2
#define MotorR2 4
#define MotorRE 3
#define trigPinR 7
#define echoPinR 8
#define trigPinL 12
#define echoPinL 13

#define MIN_DISTANCE 10
#define MAX_DISTANCE 100

// Değişkenler
long gecenSure;
int mesafeL, mesafeR;
int solspeed, sagspeed;
int solyon, soldelay, sagyon, sagdelay;
int motoryon, motorhiz, motordelay;

void setup() {
pinMode(MotorR1, OUTPUT);
pinMode(MotorR2, OUTPUT);
pinMode(MotorL1, OUTPUT);
pinMode(MotorL2, OUTPUT);
pinMode(trigPinR, OUTPUT);
pinMode(echoPinR, INPUT);
pinMode(trigPinL, OUTPUT);
pinMode(echoPinL, INPUT);
Serial.begin(9600);
delay(1000);
}

void loop() {
mesafeL = mesafeOku(trigPinL, echoPinL);
mesafeR = mesafeOku(trigPinR, echoPinR);

if (mesafeL < MIN_DISTANCE && mesafeR < MIN_DISTANCE) {
geri();
delay(400);
} else {
solspeed = motorHizi(mesafeR);
solyon = motoryon;
soldelay = motordelay;

sagspeed = motorHizi(mesafeL);
sagyon = motoryon;
sagdelay = motordelay;

if (herIkiMotorDurdu()) {
geri();
delay(400);

if (mesafeL >= mesafeR) {
solaDon();
delay(900);
Serial.println("Sola dön çalıştı");
} else {
sagaDon();
delay(900);
Serial.println("Sağa dön çalıştı");
}
} else {
motorlariCalistir(solspeed, sagspeed, solyon, sagyon, soldelay, sagdelay);
}
}
}

int mesafeOku(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
gecenSure = pulseIn(echoPin, HIGH);
int distance = (gecenSure / 2) / 29.1;
return constrain(distance, 1, 100);
}

int motorHizi(int distance) {
if(distance >= 63) {
motoryon = 1;
motorhiz = map(distance, 63, 100, 220, 255);
motordelay = 10;
} else if(distance >= 53) {
motoryon = 1;
motorhiz = map(distance, 53, 62, 180, 219);
motordelay = 20;
} else if(distance >= 43) {
motoryon = 1;
motorhiz = map(distance, 43, 52, 130, 179);
motordelay = 30;
} else if(distance >= 33) {
motoryon = 1;
motorhiz = map(distance, 33, 42, 90, 129);
motordelay = 40;
} else if(distance >= 23) {
motoryon = 1;
motorhiz = map(distance, 23, 32, 60, 89);
motordelay = 50;
} else if(distance >= 13) {
motoryon = 1;
motorhiz = map(distance, 13, 22, 40, 60);
motordelay = 60;
} else if(distance >= 6) {
motoryon = 0;
motorhiz = 40;
motordelay = 50;
} else if(distance >= 1) {
motoryon = 2;
motorhiz = map(distance, 2, 5, 40, 60);
motordelay = 40;
} else {
motoryon = 0;
motorhiz = 200;
motordelay = 50;
}
return motorhiz;
}

void motorlariCalistir(int solhiz, int saghiz, int solyon, int sagyon, int solbekleme, int sagbekleme) {
int d = max(soldelay, sagdelay);
if(solyon == 1) {
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, solhiz);
delay(d);
} else if(solyon == 0) {
digitalWrite(MotorL1, LOW);
digitalWrite(MotorL2, LOW);
delay(d);
} else {
digitalWrite(MotorL1, LOW);
digitalWrite(MotorL2, HIGH);
analogWrite(MotorLE, solhiz);
delay(d);
}
if(sagyon == 1) {
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, saghiz);
delay(d);
} else if(sagyon == 0) {
digitalWrite(MotorR1, LOW);
digitalWrite(MotorR2, LOW);
delay(d);
} else {
digitalWrite(MotorR1, LOW);
digitalWrite(MotorR2, HIGH);
analogWrite(MotorRE, saghiz);
delay(d);
}
}

void geri() {
digitalWrite(MotorR1, LOW);
digitalWrite(MotorR2, HIGH);
analogWrite(MotorRE, 100);
digitalWrite(MotorL1, LOW);
digitalWrite(MotorL2, HIGH);
analogWrite(MotorLE, 100);
}

void sagaDon() {
digitalWrite(MotorR1, LOW);
digitalWrite(MotorR2, HIGH);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, HIGH);
digitalWrite(MotorL2, LOW);
analogWrite(MotorLE, 150);
}

void solaDon() {
digitalWrite(MotorR1, HIGH);
digitalWrite(MotorR2, LOW);
analogWrite(MotorRE, 150);
digitalWrite(MotorL1, LOW);
digitalWrite(MotorL2, HIGH);
analogWrite(MotorLE, 150);
}

bool herIkiMotorDurdu() {
return mesafeL < MIN_DISTANCE && mesafeR < MIN_DISTANCE;
}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.