Nesne Takibi. Joistik ile Lazer Konum Kayıt

Renkli cisim takibi projemi biraz geliştirerek sizlerle paylaşmak istedim arkadaşlar . Ayrıntılı olarak videoda yer alan projemin dokumalarını buradan paylaşıyorum. Bilgisayar için hazırlanmış arayüzde kameradan gelen görüntüyü alarak renk filtreleme yapıyoruz. Servolar sayesinde kameramız rengi filtre edilmiş nesneyi takibe başlıyor.

Pc Arayüz Yazılım:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using AForge;
using AForge.Imaging.Filters;
using AForge.Imaging;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Math.Geometry;

using System.IO.Ports;
using System.IO;
//Remove ambiguousness between AForge.Image and System.Drawing.Image
using Point = System.Drawing.Point; //Remove ambiguousness between AForge.Point and System.Drawing.Point

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string[] ports = SerialPort.GetPortNames();

    private FilterInfoCollection VideoCapTureDevices;
    private VideoCaptureDevice Finalvideo;


    public Form1()
    {
        InitializeComponent();
    }
    int objectX;
    int objectY;
    int hedef;
    int R; //Trackbarın değişkeneleri
    int G;
    int B;


    private void Form1_Load(object sender, EventArgs e)
    {
        VideoCapTureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        foreach (FilterInfo VideoCaptureDevice in VideoCapTureDevices)
        {

            comboBox1.Items.Add(VideoCaptureDevice.Name);

        }

        comboBox1.SelectedIndex = 0;
        foreach (string port in ports)
        {
            comboBox2.Items.Add(port);
            comboBox2.SelectedIndex = 0;
        }
        comboBox3.Items.Add("2400");
        comboBox3.Items.Add("4800");
        comboBox3.Items.Add("9600");
        comboBox3.Items.Add("19200");
        comboBox3.Items.Add("115200");
        comboBox3.SelectedIndex = 2;
        //AÇILIŞTA BAĞLANTININ KAPALI OLDUĞUNU BELİRT.
        label16.Text = "Bağlantı Kapalı";
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        {
            // Form kapandığında SerialPort1 portu kapat.
            if (serialPort1.IsOpen == true)
            {
                serialPort1.Close();
            }
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        try
        {
            string sonuc = serialPort1.ReadExisting();
         
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            timer1.Stop();
        }
    }
    private void button1_Click(object sender, EventArgs e)
    {

        timer1.Start();
        if (serialPort1.IsOpen == false)
        {
            if (comboBox2.Text == "")
                return;
            serialPort1.PortName = comboBox2.Text;
            serialPort1.BaudRate = Convert.ToInt16(comboBox3.Text);
            try
            {
                serialPort1.Open();
                label16.ForeColor = Color.Green;
                label16.Text = "Bağlantı Açık";


            }
            catch (Exception hata)
            {
                MessageBox.Show("Hata:" + hata.Message);
            }
        }
        else
        {
            label16.Text = "Bağlantı kurulu !!!";
        }


        Finalvideo = new VideoCaptureDevice(VideoCapTureDevices[comboBox1.SelectedIndex].MonikerString);
        Finalvideo.NewFrame += new NewFrameEventHandler(Finalvideo_NewFrame);
        Finalvideo.DesiredFrameRate = 20;//saniyede kaç görüntü alsın istiyorsanız. FPS
        Finalvideo.DesiredFrameSize = new Size(320, 240);//görüntü boyutları
        Finalvideo.Start();
    }

    void Finalvideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {

        Bitmap image = (Bitmap)eventArgs.Frame.Clone();
        Bitmap image1 = (Bitmap)eventArgs.Frame.Clone();
        pictureBox1.Image = image;



        if (rdiobtnKirmizi.Checked)
        {

            // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center colol and radius
            filter.CenterColor = new RGB(Color.FromArgb(215, 183, 0));
            filter.Radius = 100;
            // apply the filter
            filter.ApplyInPlace(image1);


            nesnebul(image1);

        }

        if (rdiobtnMavi.Checked)
        {

            // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center color and radius
            filter.CenterColor = new RGB(Color.FromArgb(0, 255, 255));
            filter.Radius = 100;
            // apply the filter
            filter.ApplyInPlace(image1);

            nesnebul(image1);

        }
        if(rdiobtnYesil.Checked){

            // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center color and radius
            filter.CenterColor = new RGB(Color.FromArgb(98, 183, 0));
            filter.Radius = 100;
            // apply the filter
            filter.ApplyInPlace(image1);

            nesnebul(image1);



        }


        if (rdbtnElleBelirleme.Checked)
        {

             // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center colol and radius
            filter.CenterColor = new RGB(Color.FromArgb(R, G, B));
            filter.Radius = 100;
            // apply the filter
            filter.ApplyInPlace(image1);

            nesnebul(image1);

        }



    }
    public void nesnebul(Bitmap image)
    {
        BlobCounter blobCounter = new BlobCounter();
        blobCounter.MinWidth = 5;
        blobCounter.MinHeight = 5;
        blobCounter.FilterBlobs = true;
        blobCounter.ObjectsOrder = ObjectsOrder.Size;
        //Grayscale griFiltre = new Grayscale(0.2125, 0.7154, 0.0721);
        //Grayscale griFiltre = new Grayscale(0.2, 0.2, 0.2);
        //Bitmap griImage = griFiltre.Apply(image);

        BitmapData objectsData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
        // grayscaling
        Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
        UnmanagedImage grayImage = grayscaleFilter.Apply(new UnmanagedImage(objectsData));
        // unlock image
        image.UnlockBits(objectsData);


        blobCounter.ProcessImage(image);
        Rectangle[] rects = blobCounter.GetObjectsRectangles();
        Blob[] blobs = blobCounter.GetObjectsInformation();
        pictureBox2.Image = image;




            //Tekli cisim Takibi Single Tracking--------

            foreach (Rectangle recs in rects)
            {
                if (rects.Length > 0)
                {
                    Rectangle objectRect = rects[0];
                    //Graphics g = Graphics.FromImage(image);
                    Graphics g = pictureBox1.CreateGraphics();
                    using (Pen pen = new Pen(Color.FromArgb(252, 3, 26), 2))
                    {
                        g.DrawRectangle(pen, objectRect);
                    }
                    //Cizdirilen Dikdörtgenin Koordinatlari aliniyor.
                    int objectX = objectRect.X + (objectRect.Width / 2);
                    int objectY = objectRect.Y + (objectRect.Height / 2);
                    //  g.DrawString(objectX.ToString() + "X" + objectY.ToString(), new Font("Arial", 12), Brushes.Red, new System.Drawing.Point(250, 1));
                    g.Dispose();

                    this.Invoke((MethodInvoker)delegate
                    {
                        // richTextBox1.Text = objectRect.Location.ToString() + "\n" + richTextBox1.Text + "\n"; ;

                        label19.Text = objectX.ToString();
                        label20.Text = objectY.ToString();


                        //serialPort1.Write("a");
                        string angle1 = objectX.ToString();
                        string angle2 = objectY.ToString();
                        string angle3 = hedef.ToString();

                        serialPort1.WriteLine(angle1);
                        serialPort1.WriteLine(",");

                        serialPort1.WriteLine(angle2);
                        serialPort1.WriteLine(";");
                        serialPort1.WriteLine(angle3);
                        serialPort1.WriteLine(":");
                        hedef = 0;








                    });

                }
            }









    }

    // Conver list of AForge.NET's points to array of .NET points
    private Point[] ToPointsArray(List<IntPoint> points)
    {
        Point[] array = new Point[points.Count];

        for (int i = 0, n = points.Count; i < n; i++)
        {
            array[i] = new Point(points[i].X, points[i].Y);
        }

        return array;
    }

    private void button2_Click(object sender, EventArgs e)
    {

        if (Finalvideo.IsRunning)
        {
            Finalvideo.Stop();

        }
    }


    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        R = trackBar1.Value;

        label12.Text = R.ToString();
    }

    private void trackBar2_Scroll(object sender, EventArgs e)
    {
        G = trackBar2.Value;
        label13.Text = G.ToString();
    }

    private void trackBar3_Scroll(object sender, EventArgs e)
    {
        B = trackBar3.Value;

        label14.Text = B.ToString();
    }

    private void button3_Click(object sender, EventArgs e)
    {

        if (Finalvideo.IsRunning)
        {
            Finalvideo.Stop();

        }

        Application.Exit();
        timer1.Stop();
        if (serialPort1.IsOpen == true)
        {
            serialPort1.Close();
            label16.ForeColor = Color.Red;
            label16.Text = "Bağlantı Kapalı";
        }

    }

    private void button4_Click(object sender, EventArgs e)
    {
        hedef = 1;
    }
}

}

Arduino Yazılım:

#include <Servo.h> //Servo kütüphanesi
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(13 , 12, 11 , 10 , 9 , 8);
Servo horizontal;
int servoh = 90;


char Char;
Servo vertical;
int servov = 90;
int x_gelen;
int y_gelen;

int servo_x = 90;
int servo_y = 90;
int x_veri;
int y_veri;

String x, y, h;
int x_koor, y_koor, hedef;

int ax = 90;
int ay = 90;

const byte lazer = 7;
const byte buzzer = 4;
const byte led = A5;

const byte ok_pini = A0;
const byte x_pini = A1;
const byte y_pini = A2;
const byte ayar_pini = A3;
const byte buton_pini = A4;
int x_deger;
int y_deger;
int ayar_deger;
int buton_deger;
int ok_deger;


int bir_x_deger;
int bir_y_deger;

int iki_x_deger;
int iki_y_deger;

int uc_x_deger;
int uc_y_deger;

int dort_x_deger;
int dort_y_deger;

int bes_x_deger;
int bes_y_deger;

int birx = 50;                                    // eepromdaki değişken adres
int biry = 51;                                    // eepromdaki değişken adres

int ikix = 52;                                    // eepromdaki değişken adres
int ikiy = 53;                                    // eepromdaki değişken adres

int ucx = 54;                                    // eepromdaki değişken adres
int ucy = 55;                                    // eepromdaki değişken adres

int dortx = 56;                                    // eepromdaki değişken adres
int dorty = 57;                                    // eepromdaki değişken adres

int besx = 60;                                    // eepromdaki değişken adres
int besy = 61;                                    // eepromdaki değişken adres







int a = 90;
int b = 90;

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);

bir_x_deger = EEPROM.read(birx);       
iki_x_deger = EEPROM.read(ikix);      
uc_x_deger = EEPROM.read(ucx);      
dort_x_deger = EEPROM.read(dortx);    
bes_x_deger = EEPROM.read(besx);                                   // eepromdaki değişken adres


bir_y_deger = EEPROM.read(biry);       
iki_y_deger = EEPROM.read(ikiy);      
uc_y_deger = EEPROM.read(ucy);      
dort_y_deger = EEPROM.read(dorty);    
bes_y_deger = EEPROM.read(besy);                                   // eepromdaki değişken adres


  

  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(lazer, OUTPUT);
  horizontal.attach(6); // yatay
  vertical.attach(5); // dikey
  horizontal.write(90);
  vertical.write(90);


}
void loop()
{

  digitalWrite(lazer, HIGH);
  x_deger = analogRead(x_pini);
  y_deger = analogRead(y_pini);
  ayar_deger = analogRead(ayar_pini);
  ok_deger = analogRead(ok_pini);
  buton_deger = analogRead(buton_pini);


  int servo_x = map(x_deger , 0, 1023, 0, 180);
  int servo_y = map(y_deger , 0, 1023, 0, 180);
  while (ayar_deger < 150)
  {


    //-------------------------------------------------------------------



    //-------------------------------------------------------------------

    if (Serial.available() > 0)
    {

      Char = Serial.read();

      x = Serial.readStringUntil(',');
      x_koor = x.toInt();// C# - Motor-1'den Gönderilen Deger

      y = Serial.readStringUntil(';');
      y_koor = y.toInt(); // C# - Motor-2'den Gönderilen Deger

      h = Serial.readStringUntil(':');
      hedef = h.toInt(); // C# - Motor-2'den Gönderilen Deger

      lcd.setCursor (0, 0);
      lcd.print("x_koor = ");
      lcd.print( x.toInt());
      lcd.print("          ");
      lcd.setCursor (0, 1);
      lcd.print("y_koor = ");
      lcd.print(y.toInt());
      lcd.print("          ");


      //      delay(55);
      if (hedef == 1)
      {
        for (int a = 0; a < 5; a++)
        {
          digitalWrite(buzzer, 1);
          digitalWrite(lazer, LOW);
          delay(100);

          digitalWrite(lazer, HIGH);

          digitalWrite(buzzer, 0);
          delay(50);
        }
      }

      else if (x_koor > 195)
      {
        servo_x = servo_x - 1;


      }

      else if (x_koor < 145)
      {

        servo_x = servo_x + 1;
      }




      else if (y_koor > 135)
      {

        servo_y = servo_y + 1;
      }
      else if (y_koor < 105)
      {

        servo_y = servo_y - 1;

      }

      while (x_koor > 144 && x_koor < 196 && y_koor > 104 && y_koor < 136)
      {
        if (Serial.available() > 0)
        {
          Char = Serial.read();

          x = Serial.readStringUntil(',');
          x_koor = x.toInt();// C# - Motor-1'den Gönderilen Deger

          y = Serial.readStringUntil(';');
          y_koor = y.toInt(); // C# - Motor-2'den Gönderilen Deger

          h = Serial.readStringUntil(':');
          hedef = h.toInt(); // C# - Motor-2'den Gönderilen Deger
        }



        lcd.setCursor (0, 0);
        lcd.print("HEDEF SABIT     ");
        lcd.setCursor (0, 1);
        lcd.print(" DURUMDA ATES ET");



        buton_deger = analogRead(buton_pini);
        ok_deger = analogRead(ok_pini);
        if (buton_deger > 500  && buton_deger < 650  ) // 1. butonnnnnnnnnnnnnnnnnnnn
        {

          lcd.setCursor (0, 0);
          lcd.print("ARACTAN 1.SEVIYE");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 5; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(200);
            digitalWrite(lazer, HIGH);
            digitalWrite(buzzer, 0);
            delay(50);
          }
        }
        if (buton_deger > 650  && buton_deger < 700  ) // 2. butonnnnnnnnnnnnnnnnnnnn

        {

          lcd.setCursor (0, 0);
          lcd.print("ARACTAN 2.SEVIYE");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 7; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(200);
            digitalWrite(lazer, HIGH);
            digitalWrite(buzzer, 0);
            delay(50);
          }
        }

        if (buton_deger > 700  && buton_deger < 750   ) // 3. butonnnnnnnnnnnnnnnnnnnn
        {

          lcd.setCursor (0, 0);
          lcd.print("ARACTAN 3.SEVIYE");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 5; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(300);
            digitalWrite(lazer, HIGH);
            digitalWrite(buzzer, 0);
            delay(50);
          }
        }
        if (buton_deger > 750  && buton_deger < 800  ) // 4. butonnnnnnnnnnnnnnnnnnnn

        {

          lcd.setCursor (0, 0);
          lcd.print("ARACTAN 4.SEVIYE");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 7; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(300);
            digitalWrite(lazer, HIGH);
            digitalWrite(buzzer, 0);
            delay(50);
          }
        }
        if (buton_deger > 800  && buton_deger < 900 ) // 5. butonnnnnnnnnnnnnnnnnnnn
        {

          lcd.setCursor (0, 0);
          lcd.print("ARACTAN 5.SEVIYE");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 5; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(500);
            digitalWrite(lazer, HIGH);
            digitalWrite(buzzer, 0);
            delay(150);
          }
        }
        if (hedef == 1)
        {

          lcd.setCursor (0, 0);
          lcd.print(" BILGISAYARDAN  ");
          lcd.setCursor (0, 1);
          lcd.print("  ATES EDILDI   ");
          for (int a = 0; a < 5; a++)
          {
            digitalWrite(buzzer, 1);
            digitalWrite(lazer, LOW);
            delay(100);

            digitalWrite(lazer, HIGH);

            digitalWrite(buzzer, 0);
            delay(50);
          }


        }
        horizontal.write(servo_x);
        vertical.write(servo_y);
      }


      if (servo_x > 180)
      {
        servo_x = 180;
      }

      if (servo_x < 0)
      {
        servo_x = 0;
      }
      if (servo_y  > 170)
      {
        servo_y = 170;
      }
      if (servo_y  < 20)
      {
        servo_y = 20;
      }
      horizontal.write(servo_x);
      vertical.write(servo_y);




    }


    else
    {

      lcd.setCursor (0, 0);
      lcd.print("BAGLANTI KURUNUZ");
      lcd.setCursor (0, 1);
      lcd.print("  HEDEF SECINIZ ");
    }


    ayar_deger = analogRead(ayar_pini);
  }


  lcd.clear();
  while (ayar_deger > 150 && ayar_deger < 250)
  {

    ok_deger = analogRead(ok_pini);
    buton_deger = analogRead(buton_pini);
    x_deger = analogRead(x_pini);
    y_deger = analogRead(y_pini);
    int servo_x = map(x_deger , 0, 1023, 0, 180);
    int servo_y = map(y_deger , 0, 1023, 0, 180);
    Serial.print("servo_x ");
    Serial.print(servo_x);
    Serial.print( "  servo_y ");
    Serial.println(servo_y);

    if (servo_x > 120)
    {
      a++;
      if (a > 180)
        a = 180;
      horizontal.write(a);
    }
    else if (servo_x < 60)
    {
      a--;
      if (a < 0)
        a = 0;
      horizontal.write(a);
    }
    else if (servo_y > 120)
    {
      b++;
      if (b > 180)
        b = 180;
      vertical.write(b);
    }
    else  if (servo_y < 60)
    {
      b--;
      if (b < 0)
        b = 0;
      vertical.write(b);
    }
    if (buton_deger > 900)
    {
      a = 90;
      b = 90;
      horizontal.write(a);
      vertical.write(b);

    }
    lcd.setCursor (0, 0);
    lcd.print("1> ");
    lcd.setCursor (3, 0);
    lcd.print("x =");
    lcd.print(a);
    lcd.print(" ");
    lcd.setCursor (9, 0);
    lcd.print(" y =");
    lcd.print(b);
    lcd.print("                ");

    lcd.setCursor (3, 1);
    lcd.print("x =");
    lcd.print(bir_x_deger);
    lcd.print(" ");
    lcd.setCursor (9, 1);
    lcd.print(" y =");
    lcd.print(bir_y_deger);
    lcd.print("                ");
    digitalWrite(led , LOW);
    //----------------------------------------------------------------------

    buton_deger = analogRead(buton_pini);
    if (buton_deger > 500 && buton_deger < 650 || ok_deger < 500 )
    {


      bir_x_deger = a;
      bir_y_deger = b;


      lcd.setCursor (0, 1);
      lcd.print("1>>");
      lcd.setCursor (3, 1);
      lcd.print("x =");
      lcd.print(bir_x_deger);
      lcd.print(" ");
      lcd.setCursor (9, 1);
      lcd.print(" y =");
      lcd.print(bir_y_deger);
      lcd.print("                ");

      digitalWrite(led , HIGH);
      delay(1000);

    }


    //----------------------------------------------------------------------
    ayar_deger = analogRead(ayar_pini);
    delay(50);

  }

  lcd.clear();

  while (ayar_deger > 250 && ayar_deger < 390)
  {

    digitalWrite(led , LOW);

    ok_deger = analogRead(ok_pini);
    buton_deger = analogRead(buton_pini);
    x_deger = analogRead(x_pini);
    y_deger = analogRead(y_pini);
    int servo_x = map(x_deger , 0, 1023, 0, 180);
    int servo_y = map(y_deger , 0, 1023, 0, 180);

    if (servo_x > 120)
    {
      a++;
      if (a > 180)
        a = 180;
      horizontal.write(a);
    }
    else if (servo_x < 60)
    {
      a--;
      if (a < 0)
        a = 0;
      horizontal.write(a);
    }
    else if (servo_y > 120)
    {
      b++;
      if (b > 180)
        b = 180;
      vertical.write(b);
    }
    else  if (servo_y < 60)
    {
      b--;
      if (b < 0)
        b = 0;
      vertical.write(b);
    }

    if (buton_deger > 900)
    {
      a = 90;
      b = 90;
      horizontal.write(a);
      vertical.write(b);

    }

    lcd.setCursor (0, 0);
    lcd.print("2> ");
    lcd.setCursor (3, 0);
    lcd.print("x =");
    lcd.print(a);
    lcd.print(" ");
    lcd.setCursor (9, 0);
    lcd.print(" y =");
    lcd.print(b);
    lcd.print("                ");

    lcd.setCursor (3, 1);
    lcd.print("x =");
    lcd.print(iki_x_deger);
    lcd.print(" ");
    lcd.setCursor (9, 1);
    lcd.print(" y =");
    lcd.print(iki_y_deger);
    lcd.print("                ");
    buton_deger = analogRead(buton_pini);


    if (buton_deger > 650  && buton_deger < 700  || ok_deger < 500 ) // 2. butonnnnnnnnnnnnnnnnnnnn
    {


      iki_x_deger = a;
      iki_y_deger = b;


      lcd.setCursor (0, 1);
      lcd.print("2>>");
      lcd.setCursor (3, 1);
      lcd.print("x =");
      lcd.print(iki_x_deger);
      lcd.print(" ");
      lcd.setCursor (9, 1);
      lcd.print(" y =");
      lcd.print(iki_y_deger);
      lcd.print("                ");

      digitalWrite(led , HIGH);
      delay(1000);
    }


    ayar_deger = analogRead(ayar_pini);
    delay(50);

  }

  lcd.clear();

  while (ayar_deger > 390 && ayar_deger < 625)
  {

    digitalWrite(led , LOW);

    ok_deger = analogRead(ok_pini);
    buton_deger = analogRead(buton_pini);
    x_deger = analogRead(x_pini);
    y_deger = analogRead(y_pini);
    int servo_x = map(x_deger , 0, 1023, 0, 180);
    int servo_y = map(y_deger , 0, 1023, 0, 180);
    if (servo_x > 120)
    {
      a++;
      if (a > 180)
        a = 180;
      horizontal.write(a);
    }
    else if (servo_x < 60)
    {
      a--;
      if (a < 0)
        a = 0;
      horizontal.write(a);
    }
    else if (servo_y > 120)
    {
      b++;
      if (b > 180)
        b = 180;
      vertical.write(b);
    }
    else  if (servo_y < 60)
    {
      b--;
      if (b < 0)
        b = 0;
      vertical.write(b);
    }

    if (buton_deger > 900)
    {
      a = 90;
      b = 90;
      horizontal.write(a);
      vertical.write(b);

    }

    lcd.setCursor (0, 0);
    lcd.print("3> ");
    lcd.setCursor (3, 0);
    lcd.print("x =");
    lcd.print(a);
    lcd.print(" ");
    lcd.setCursor (9, 0);
    lcd.print(" y =");
    lcd.print(b);
    lcd.print("                ");

    lcd.setCursor (3, 1);
    lcd.print("x =");
    lcd.print(uc_x_deger);
    lcd.print(" ");
    lcd.setCursor (9, 1);
    lcd.print(" y =");
    lcd.print(uc_y_deger);
    lcd.print("                ");
    buton_deger = analogRead(buton_pini);
    if (buton_deger > 700  && buton_deger < 750 || ok_deger < 500 ) // 3. butonnnnnnnnnnnnnnnnnnnn
    {


      uc_x_deger = a;
      uc_y_deger = b;


      lcd.setCursor (0, 1);
      lcd.print("3>>");
      lcd.setCursor (3, 1);
      lcd.print("x =");
      lcd.print(uc_x_deger);
      lcd.print(" ");
      lcd.setCursor (9, 1);
      lcd.print(" y =");
      lcd.print(uc_y_deger);
      lcd.print("                ");

      digitalWrite(led , HIGH);
      delay(1000);
    }


    ayar_deger = analogRead(ayar_pini);
    delay(50);

  }

  lcd.clear();

  while (ayar_deger > 625 && ayar_deger < 870)
  {
    digitalWrite(led , LOW);

    ok_deger = analogRead(ok_pini);
    buton_deger = analogRead(buton_pini);
    x_deger = analogRead(x_pini);
    y_deger = analogRead(y_pini);
    int servo_x = map(x_deger , 0, 1023, 0, 180);
    int servo_y = map(y_deger , 0, 1023, 0, 180);

    if (servo_x > 120)
    {
      a++;
      if (a > 180)
        a = 180;
      horizontal.write(a);
    }
    else if (servo_x < 60)
    {
      a--;
      if (a < 0)
        a = 0;
      horizontal.write(a);
    }
    else if (servo_y > 120)
    {
      b++;
      if (b > 180)
        b = 180;
      vertical.write(b);
    }
    else  if (servo_y < 60)
    {
      b--;
      if (b < 0)
        b = 0;
      vertical.write(b);
    }

    if (buton_deger > 900)
    {
      a = 90;
      b = 90;
      horizontal.write(a);
      vertical.write(b);

    }
    lcd.setCursor (0, 0);
    lcd.print("4> ");
    lcd.setCursor (3, 0);
    lcd.print("x =");
    lcd.print(a);
    lcd.print(" ");
    lcd.setCursor (9, 0);
    lcd.print(" y =");
    lcd.print(b);
    lcd.print("                ");


    lcd.setCursor (3, 1);
    lcd.print("x =");
    lcd.print(dort_x_deger);
    lcd.print(" ");
    lcd.setCursor (9, 1);
    lcd.print(" y =");
    lcd.print(dort_y_deger);
    lcd.print("                ");
    buton_deger = analogRead(buton_pini);
    if (buton_deger > 750  && buton_deger < 800  || ok_deger < 500 ) // 4. butonnnnnnnnnnnnnnnnnnnn
    {


      dort_x_deger = a;
      dort_y_deger = b;


      lcd.setCursor (0, 1);
      lcd.print("4>>");
      lcd.setCursor (3, 1);
      lcd.print("x =");
      lcd.print(dort_x_deger);
      lcd.print(" ");
      lcd.setCursor (9, 1);
      lcd.print(" y =");
      lcd.print(dort_y_deger);
      lcd.print("                ");

      digitalWrite(led , HIGH);
      delay(1000);
    }


    ayar_deger = analogRead(ayar_pini);
    delay(50);

  }

  lcd.clear();




  EEPROM.write(birx,(bir_x_deger));
  EEPROM.write(ikix,(iki_x_deger));
  EEPROM.write(ucx,(uc_x_deger));
  EEPROM.write(dortx,(dort_x_deger));
  EEPROM.write(besx,(bes_x_deger));     


  EEPROM.write(biry,(bir_y_deger));
  EEPROM.write(ikiy,(iki_y_deger));
  EEPROM.write(ucy,(uc_y_deger));
  EEPROM.write(dorty,(dort_y_deger));
  EEPROM.write(besy,(bes_y_deger));                 // eeprom adrese değeri yaz

  
  while (ayar_deger > 870 && ayar_deger < 990)
  {

    digitalWrite(led , LOW);

    ok_deger = analogRead(ok_pini);
    buton_deger = analogRead(buton_pini);
    x_deger = analogRead(x_pini);
    y_deger = analogRead(y_pini);
    int servo_x = map(x_deger , 0, 1023, 0, 180);
    int servo_y = map(y_deger , 0, 1023, 0, 180);
    if (servo_x > 120)
    {
      a++;
      if (a > 180)
        a = 180;
      horizontal.write(a);
    }
    else if (servo_x < 60)
    {
      a--;
      if (a < 0)
        a = 0;
      horizontal.write(a);
    }
    else if (servo_y > 120)
    {
      b++;
      if (b > 180)
        b = 180;
      vertical.write(b);
    }
    else  if (servo_y < 60)
    {
      b--;
      if (b < 0)
        b = 0;
      vertical.write(b);
    }


    if (buton_deger > 900)
    {
      a = 90;
      b = 90;
      horizontal.write(a);
      vertical.write(b);

    }

    lcd.setCursor (0, 0);
    lcd.print("5> ");
    lcd.setCursor (3, 0);
    lcd.print("x =");
    lcd.print(a);
    lcd.print(" ");
    lcd.setCursor (9, 0);
    lcd.print(" y =");
    lcd.print(b);
    lcd.print("                ");

    lcd.setCursor (3, 1);
    lcd.print("x =");
    lcd.print(bes_x_deger);
    lcd.print(" ");
    lcd.setCursor (9, 1);
    lcd.print(" y =");
    lcd.print(bes_y_deger);
    lcd.print("                ");
    buton_deger = analogRead(buton_pini);
    if (buton_deger > 800 && buton_deger < 900 || ok_deger < 500 ) // 5. butonnnnnnnnnnnnnnnnnnnn
    {


      bes_x_deger = a;
      bes_y_deger = b;


      lcd.setCursor (0, 1);
      lcd.print("5>>");
      lcd.setCursor (3, 1);
      lcd.print("x =");
      lcd.print(bes_x_deger);
      lcd.print(" ");
      lcd.setCursor (9, 1);
      lcd.print(" y =");
      lcd.print(bes_y_deger);
      lcd.print("                ");

      digitalWrite(led , HIGH);
      delay(1000);
    }


    ayar_deger = analogRead(ayar_pini);
    delay(50);

  }

  lcd.clear();
ax=90;
ay=90;
  horizontal.write(90);
  vertical.write(90);
  while (ayar_deger > 990)   // pot kitap sec konum
  {


    lcd.setCursor (0, 0);
    lcd.print("Kitap Seciniz   ");

    digitalWrite(led , LOW);
    buton_deger = analogRead(buton_pini);
    if (buton_deger > 500 && buton_deger < 650 )// 1 e git
    {

      lcd.setCursor (14, 0);
      lcd.print("1.");
      
     
while (ax < bir_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("1>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax++;
}



while (ax > bir_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("1>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax--;
}



while (ay < bir_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("1>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay++;
}

while (ay > bir_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("1>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay--;
}




      digitalWrite(led , HIGH);
      delay(1000);

      for (int a = 0; a < 5; a++)
      {
        digitalWrite(buzzer, 1);
        digitalWrite(lazer, LOW);
        delay(100);

        digitalWrite(lazer, HIGH);

        digitalWrite(buzzer, 0);
        delay(50);
      }

lcd.setCursor (0, 1);
        lcd.print("SIFIRLAMA >< BAS");
    }
    if (buton_deger > 650  && buton_deger < 700 )// 2 e git
    {
      lcd.setCursor (14, 0);
      lcd.print("2.");

      //      horizontal.write(iki_x_deger);
      //      vertical.write(iki_y_deger);


     
     
while (ax < iki_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("2>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax++;
}



while (ax > iki_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("2>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax--;
}



while (ay < iki_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("2>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay++;
}

while (ay > iki_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("2>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay--;
}



      digitalWrite(led , HIGH);
      delay(1000);
      for (int a = 0; a < 5; a++)
      {
        digitalWrite(buzzer, 1);
        digitalWrite(lazer, LOW);
        delay(100);

        digitalWrite(lazer, HIGH);

        digitalWrite(buzzer, 0);
        delay(50);
      }
lcd.setCursor (0, 1);
        lcd.print("SIFIRLAMA >< BAS");
    }
    if (buton_deger > 700  && buton_deger < 750 )// 3 e git
    {

      digitalWrite(led , HIGH);
      lcd.setCursor (14, 0);
      lcd.print("3.");
      //      horizontal.write(uc_x_deger);
      //      vertical.write(uc_y_deger);


     
while (ax < uc_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("3>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax++;
}



while (ax > uc_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("3>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax--;
}



while (ay < uc_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("3>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay++;
}

while (ay > uc_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("3>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay--;
}









      delay(1000); for (int a = 0; a < 5; a++)
      {
        digitalWrite(buzzer, 1);
        digitalWrite(lazer, LOW);
        delay(100);

        digitalWrite(lazer, HIGH);

        digitalWrite(buzzer, 0);
        delay(50);
      }
lcd.setCursor (0, 1);
        lcd.print("SIFIRLAMA >< BAS");
    }

    if (buton_deger > 750  && buton_deger < 800 )// 4 e git
    {

      digitalWrite(led , HIGH);
      lcd.setCursor (14, 0);
      //      horizontal.write(dort_x_deger);
      //      vertical.write(dort_y_deger);



     
while (ax < dort_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("4>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax++;
}



while (ax > dort_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("4>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax--;
}



while (ay < dort_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("4>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay++;
}

while (ay > dort_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("4>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay--;
}



      delay(1000); for (int a = 0; a < 5; a++)
      {
        digitalWrite(buzzer, 1);
        digitalWrite(lazer, LOW);
        delay(100);

        digitalWrite(lazer, HIGH);

        digitalWrite(buzzer, 0);
        delay(50);
      }

lcd.setCursor (0, 1);
        lcd.print("SIFIRLAMA >< BAS");
    }

    if (buton_deger > 800  && buton_deger < 900 ) // 5 e git
    {

      digitalWrite(led , HIGH);
      lcd.setCursor (14, 0);


while (ax < bes_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("5>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax++;
}



while (ax > bes_x_deger)
{
  
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("5>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ax--;
}



while (ay < bes_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("5>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay++;
}

while (ay > bes_y_deger)
{
  
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("5>>");
        lcd.setCursor (3, 1);
        lcd.print("x =");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
        ay--;
}

      delay(1000); for (int a = 0; a < 5; a++)
      {
        digitalWrite(buzzer, 1);
        digitalWrite(lazer, LOW);
        delay(100);

        digitalWrite(lazer, HIGH);

        digitalWrite(buzzer, 0);
        delay(50);
      }

lcd.setCursor (0, 1);
        lcd.print("SIFIRLAMA >< BAS");
    }
    if ( buton_deger > 900 ) // ortala
    {

      lcd.setCursor (0, 0);
      lcd.print("Makanizma Ortaya");
      lcd.setCursor (0, 1);
      lcd.print("    ALINIYOR    ");

      delay(1000);
      
      lcd.setCursor (0, 0);
      lcd.print(">>>>>>>><<<<<<<<");
      lcd.setCursor (0, 1);
      lcd.print("ax ");
      lcd.print(ax);
      lcd.print("  ay ");
      lcd.print(ay);
      lcd.print("                  ");
      while (ax > 90)
      {
        ax--;
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("  x = ");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
      }
      while (ax < 90)
      {
        ax++;
        horizontal.write(ax);
        lcd.setCursor (0, 1);
        lcd.print("  x = ");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
      }
      while (ay > 90)
      {
        ay--;
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("  x = ");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
      }
      while (ay < 90)
      {
        ay++;
        vertical.write(ay);
        lcd.setCursor (0, 1);
        lcd.print("  x = ");
        lcd.print(ax);
        lcd.print("  ");
        lcd.setCursor (9, 1);
        lcd.print(" y =");
        lcd.print(ay);
        lcd.print("                ");
        delay(50);
      }



      delay(1000);

      lcd.setCursor (0, 1);
      lcd.print("BUTON 1-2-3-4-5-");
    }
    ayar_deger = analogRead(ayar_pini);

  }




  //  delay(200);

  //  }




}

Sosyal Medyada Paylaş Facebook Twitter Google+

Etiketler: , , , , , , , , ,
Eklenme Tarihi: 16 Haziran 2019

Konu hakkında yorumunuzu yazın

Nesne Takibi. Joistik ile Lazer Konum Kayıt (2 Yorum)

    • Vusial studio programında arayüz oluşturmanız lazım. Bana whatsapp tan mesaj atın hazır arayüz indirme linkini atayım.

HOŞ GELDİNİZ

Youtube kanalıma Abone Olabilirsiniz.