#include <QTRSensors.h>
#define tabanhiz 150
#define sagmotor1 10
#define sagmotor2 9
#define sagmotorpwmpin 11
#define solmotor1 6
#define solmotor2 7
#define solmotorpwmpin 5
#define MZ80 8
#define taktik 12
#define LED 13
QTRSensorsAnalog qtra((unsigned char[]) { A0, A1, A2, A3, A4, A5, A6, A7} , 8);
unsigned int sensors[8];
float Kp = 0.04; float Kd = 0.6; float Ki = 0.0001; int integral = 0;
int ekhiz = 0; int sonhata = 0; int hata = 0; byte K=0;
int sagmotorpwm = 0; int solmotorpwm = 0; unsigned char zemin = 1;
int cizgisay=0; long baslamazamani=0; long doksanzamani=50000;
void setup()
{
pinMode(sagmotor1, OUTPUT);
pinMode(sagmotor2, OUTPUT);
pinMode(sagmotorpwmpin, OUTPUT);
pinMode(solmotor1, OUTPUT);
pinMode(solmotor2, OUTPUT);
pinMode(solmotorpwmpin, OUTPUT);
pinMode(MZ80, INPUT);
pinMode(taktik, INPUT_PULLUP);
delay(1000);
digitalWrite(LED, HIGH);
for (int i = 0; i< 150; i++)
{
if (0 <= i && i < 5) hafifsagadon();
if (5 <= i && i < 15) hafifsoladon();
if (15 <= i && i < 25) hafifsagadon();
if (25 <= i && i < 35) hafifsoladon();
if (35 <= i && i < 40) hafifsagadon();
if (45 <= i && i < 50) hafifsoladon();
if (i >= 50) {
frenle(1);
delay(3);
}
qtra.calibrate();
delay(1);
}
flashyap();
while (digitalRead(MZ80) == LOW) {frenle(1);}
}
void loop() {
sensoroku();
dikcizgioku();
yol_ayrimi();
sag_sol_90();
engeldenatla();
if(cizgisay==1 || cizgisay==3 ) ekhiz=100; else ekhiz=0;
if(cizgisay==3) K=1;
if(cizgisay==5) {frenle(10000);}
if(200<(millis()-doksanzamani) && (millis()-doksanzamani)<1200 ) ekhiz=100;
if(1200<(millis()-doksanzamani) && (millis()-doksanzamani)<2400 ) ekhiz=-30;
if(2400<(millis()-doksanzamani) && (millis()-doksanzamani)<5000 ) ekhiz=100;
integral += hata;
if (abs(hata) < 500)integral = 0;
int duzeltmehizi = Kp * hata + Kd * (hata - sonhata) + Ki * integral;
sonhata = hata;
sagmotorpwm = constrain(sagmotorpwm, -50, 254);
solmotorpwm = constrain(solmotorpwm, -50, 254);
motorkontrol(solmotorpwm, sagmotorpwm);
}
void motorkontrol(int solmotorpwm,int sagmotorpwm) {
if(sagmotorpwm<=0) {
sagmotorpwm=abs(sagmotorpwm);
digitalWrite(sagmotor1, LOW);
digitalWrite(sagmotor2, HIGH);
analogWrite(sagmotorpwmpin, sagmotorpwm);
}
else {
digitalWrite(sagmotor1, HIGH);
digitalWrite(sagmotor2, LOW);
analogWrite(sagmotorpwmpin, sagmotorpwm);
}
if(solmotorpwm<=0) {
solmotorpwm=abs(solmotorpwm);
digitalWrite(solmotor1, LOW);
digitalWrite(solmotor2, HIGH);
analogWrite(solmotorpwmpin, solmotorpwm);
}
else {
digitalWrite(solmotor1, HIGH);
digitalWrite(solmotor2, LOW);
analogWrite(solmotorpwmpin, solmotorpwm);
}
}
void engeldenatla(){
if(digitalRead(MZ80) == LOW) {
motorkontrol(0,150);delay(300);
motorkontrol(150,150);delay(200);
motorkontrol(150,0);delay(250);
motorkontrol(150,150);delay(800);
motorkontrol(150,0);delay(100);
do { sensoroku(); motorkontrol(150,120); }
while(hata==0);
}
}
void sag_sol_90(){
if (sensors[0]<100 && sensors[1]<100 && sensors[2]<100 && sensors[3] && sensors[6]>500 && sensors[7]>700){
doksanzamani=millis();
do {sensoroku(); motorkontrol(200,-50);}
while(hata ==-3500);
}
if (sensors[7]<100 && sensors[6]<100 && sensors[5]<100 && sensors[4]<100 && sensors[1]>500 && sensors[0]>700){
doksanzamani=millis();
do {sensoroku(); motorkontrol(-50,200);}
while(hata ==3500);
}
void yol_ayrimi(){
if(sensors[0]>800 && sensors[2]<600 && sensors[3]<100 && sensors[4]<100 && sensors[5]<600 && sensors[7]>800){
if(K==0) {
motorkontrol(80,180);delay(300); }
if(K==1) {
motorkontrol(180,80);delay(300); }
}
}
void sensoroku(){
unsigned int position = qtra.readLine(sensors,1,zemin);
hata= position-3500;
if( sensors[0]<100 && sensors[7]<100 ) {zemin=0; }//beyaz
if( sensors[0]>750 && sensors[7]>750 ) {zemin=1; }//siyah
}
void flashyap(){
for (int x = 0; x < 6; x++) {
digitalWrite(LED, HIGH); delay(200);
digitalWrite(LED, LOW); delay(200);
}
}
void dikcizgioku(){
if (sensors[0]<100 && sensors[1]<100&& sensors[2]<100 && sensors[3]<100 &&
sensors[4]<100 && sensors[5]<100 && sensors[6]<100 && sensors[7]<100){
cizgisay++; motorkontrol(tabanhiz,tabanhiz); delay(50);
}
}
void sensorlerioku_yaz(){
for (unsigned char z = 0; z < 8; z++)
{
Serial.print(sensors[z];
Serial.print('\t');
}
Serial.println();
delay(250);
}
void frenle(int bekle){motorkontrol(0,0); delay(bekle);}
void hafifsagadon(){motorkontrol(60,-60);}
void hafifsoladon(){motorkontrol(-60,60);}
KODLARDA HATA VAR YARDIM EDEBİLECEK OLAN VAR MI
error: ‘frenle’ was not declared in this scope GENELDE BU HATALAR VAR TÜM FONKSİYONLARDA