Quantcast
Viewing all articles
Browse latest Browse all 1768

Serial communication processing.

Hello,

As part of my project robot control computer I need a program that can send commands via the serial port (the side of the robot while running test with Arduino board serial monitor) so I chose processing but the program does not send the code, so you can help to find the error in the program me.

  1. /*
    avant = 1
    ariere = 2
    gauche = 3
    droite = 4
    stop = 5
    auto = 6
    manuelle = 7

    */




    import interfascia.*;
    import processing.serial.*;
    Serial port;


    GUIController c;

    IFButton av, ar, g, d, s, a, m;



    int controle ;
    int controle1 ;


    void setup() {
     
      size(600, 600);
      port = new Serial(this, "COM6", 9600);
      port.bufferUntil('\n');
      println("connecter");
     
      background(155);
     
      c = new GUIController (this);
     
     
      av = new IFButton ("Avant", 250, 130, 80, 80);
      ar = new IFButton ("Ariere", 250, 370, 80, 80);
      g = new IFButton ("Gauche", 130, 250, 80, 80);
      d = new IFButton ("Droite", 370, 250, 80, 80);
      s = new IFButton ("Stop", 250, 250, 80, 80);
      a = new IFButton ("Automatique", 15, 550, 80, 30);
      m = new IFButton ("Manuelle", 100, 550, 80, 30);
     
     
     

      av.addActionListener(this);
      ar.addActionListener(this);
      g.addActionListener(this);
      d.addActionListener(this);
      s.addActionListener(this);
      a.addActionListener(this);
      m.addActionListener(this);

      c.add (av);
      c.add (ar);
      c.add (g);
      c.add (d);
      c.add (s);
      c.add (a);
      c.add (m);

     
    }

    void draw() {

    }





    //Debut commande au clavier
    void keyPressed(){
     
       if (keyCode == UP)
      {
        println("AVANT");
        int controle = 1;
        println("commande " + controle);
       

      }
      else if (keyCode == DOWN) {
        int controle = 2;
        println("commande " + controle);
        println("ARIERE");
       

      }
      else if (keyCode == LEFT) {
        int controle = 3;
        println("commande " + controle);
        println("GAUCHE");
       

      }
      else if (keyCode == RIGHT) {
        int controle = 4;
        println("commande " + controle);
        println("DROITE");
       

      }
      else if (key == 'a') {
        int controle1 = 6;
        println("commande1 " + controle);
        println("Automatique");
       

      }
      else if (key == 'm') {
        int controle1 = 7;
        println("commande1 " + controle1);
        println("Manuelle");
       

      }
      else{
       println("STOP");
       int controle = 5;
       println("commande " + controle1);

      }
     
    }
    //Fin commande au clavier






    //Debut commande a la sourie(écran)

    void actionPerformed (GUIEvent e) {
     
      if (e.getSource() == av)               //AV
      {
      
        println("Avant");
        int controle = 1;
        println("commande " + controle);

      }
     
      else if (e.getSource() == ar)          //AR
      {
       
        println("Arriere");
        int controle = 2;
        println("commande " + controle);

      }
     
      else if (e.getSource() == g)           //G
      {
       
        println("Gauche");
        int controle = 3;
        println("commande " + controle);

      }
     
      else if (e.getSource() == d)           //D
      {
       
        println("Droite");
        int controle = 4;
        println("commande " + controle);

      }
     
      else if (e.getSource() == s)           //S
      {
       
        println("Stop");
        int controle = 5;
        println("commande " + controle);

      }
      else if (e.getSource() == a)           //S
      {
       
        println("Automatique");
        int controle1 = 6;
        println("commande1 " + controle1);
       

      }
      else if (e.getSource() == m)           //S
      {
       
        println("Manuelle");
        int controle1 = 7;
        println("commande1 " + controle1);
       
      }
      else{
         println("Rien");
        int controle1 = 9;
        println("commande1 " + controle1);
      }

      
      }
      //Fin commande a la sourie(écran)

      //Envoi de la commande de controle
      void serialEvent (Serial port)
      {
        println("hbbhbhbgbhbhhj");
         port.write(controle1);
         port.write(controle);
         println("envoyer");
       
        
      }


Viewing all articles
Browse latest Browse all 1768

Trending Articles