How to put the data received by the serial port into a variable?

edited March 2017 in Arduino

I have an arduino program that displays the value of a potetiometer, I can display it in the processing processing but I can not put the value of the data sent in a variable? I would do this so that the potentiometer can change the value of a slider controlp5

Thanks you

Tagged:

Answers

  • You should provide some code showing your approach or you could browse previous related posts: https://forum.processing.org/two/search?Search=arduino

    Kf

  • edited March 2017
            //importation des différentes librairies
            import ketai.net.nfc.record.*;
            import ketai.camera.*;
            import ketai.net.*;
            import ketai.ui.*;
            import ketai.cv.facedetector.*;
            import ketai.sensors.*;
            import ketai.net.nfc.*;
            import ketai.data.*;
            import ketai.net.bluetooth.*;
    
            import controlP5.*;
    
            import android.content.Intent;
            import android.os.Bundle;
            import ketai.net.bluetooth.*;
            import ketai.ui.*;
            import ketai.net.*;
    
            PFont fontMy;
            boolean bReleased = true; //Pas de changement d'état de la réponse si le doigt reste //appuyé sur l'écran.
            KetaiBluetooth bt;
            boolean isConfiguring = true;
            String info = "";
            KetaiList klist;
            ArrayList devicesDiscovered = new ArrayList();
    
            ControlP5 cp5;
    
            int c1,c2;
    
            float n,n1;
    
            PFont p = createFont("Arial",40);
    
            int sliderValue = 100;
    
            Textarea myTextarea;
    
            int c = 0;
    
            int value_vit = 1;
    
            int value_inc = 180;
    
            Println console;
    
            void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             bt = new KetaiBluetooth(this);
            }
    
            void onActivityResult(int requestCode, int resultCode, Intent data) {
             bt.onActivityResult(requestCode, resultCode, data);
            }
    
    
    
    
    
    
    
            void setup () {
            size (displayWidth, displayHeight); // taille de la fenètre en pleine écran
            orientation(LANDSCAPE);   // fixe l'orientation en paysage
            background(255); // mets le fond en blanc
    
             cp5 = new ControlP5(this);
    
             // create a new button with name 'buttonA'
              cp5.addButton("Gauche")
                 .setValue(0)
                 .setPosition(width/15,height/1.45)
                 .setSize(width/11,height/7)
                 .setColorBackground(color(0,5,112))
                 .setFont(createFont("arial",width/60))
                 ;
              cp5.addButton("Droite")
                 .setValue(0)
                 .setPosition(width/5,height/1.45)
                 .setSize(width/11,height/7)
                 .setColorBackground(color(0,5,112))
                 .setFont(createFont("arial",width/60))
                 ;  
    
              cp5.addButton("Arret")
                 .setValue(0)
                 .setPosition(20 , height/5)
                 .setSize(width/5,height/4)
                 .setColorBackground(color(255,5,5))
                 .setFont(createFont("arial",width/60))
                 ;
    
              cp5.addButton("Pause")
                 .setValue(0)
                 .setPosition(width/3 , height/1.45)
                 .setSize(width/11,height/7)
                 .setColorBackground(color(0,5,112))
                 .setFont(createFont("arial",width/60))
                 ;
    
              cp5.addKnob("Vitesse")
                 .setValue(value_vit)
                 .setPosition(width/1.55 , height/8)
                 .setSize(width/5,height/3)
                 .setColorBackground(color(0,5,112))
                 .setFont(createFont("arial",width/60))
                 .setNumberOfTickMarks(20)
                 ;
    
             cp5.addKnob("Inclinaison")
                 .setValue(value_inc)
                 .setPosition(width/1.55 , height/1.65)
                 .setMax(360)
                 .setSize(width/5,height/3)
                 .setColorBackground(color(0,5,112))
                 .setFont(createFont("arial",width/60))
                 .setNumberOfTickMarks(20)
                 .setViewStyle(Knob.ELLIPSE)
                 .setColorForeground(color(255))
                 .setColorBackground(color(255, 178, 34))
                 ;
    
                 //Console
    
              cp5.enableShortcuts();
    
              frameRate(500);
    
             //Début de connexion Bluetooth.
             bt.start();
             //Sélection de l'application.
             isConfiguring = true;
    
             //Couleur de fond
             fontMy = createFont("SansSerif", 40);
             textFont(fontMy);
             textSize(50);
              text("humanimer", 280, 55);
    
            }
    
    
    
    
    
    
    
    
            void draw () {
    
            //carré humanimer  
            fill(0,5,112);
            noStroke();
            rect(0,0,width/2,height/6);
    
    
            //ligne médiane vertical
            fill(0,5,112);
            noStroke();
            rect(width/2,0,width/90 ,height);
    
            //ligne médiane horizontal
            fill(0,5,112);
            noStroke();
            rect(0,height/2 ,width ,height/60);
    
            //ligne séparatrice carré gauche
            fill(0,5,112);
            noStroke();
            rect(width/4,0,width/90 ,height/2);
    
            //contour fenetre
            noFill();
            stroke(0,5,112);
            strokeWeight(width/75);
            rect(0, 0, width, height);
    
            //écriture nom
            fill (255);
            textSize(width/22);
            text("HUMANIMER", width/5, height/10);
    
            //écriture de vitesse(noeuds) 
            fill (0,5,112);
            textSize(width/40);
            text("Vitesse (Noeuds) ", width/1.5, height/15);
    
            //écriture inclinaison (degré)
            fill (0,5,112);
            textSize(width/40);
            text("Inclinaison (Degré) ", width/1.50, height/1.75);
    
            //écriture de activation
            fill (0,5,112);
            textSize(width/60);
            text("Etat du winch", width/3.2, height/7);
    
            //écriture commander le winch
            fill (0,5,112);
            textSize(width/40);
            text("Commander le winch ", width/8, height/1.75);
    
             //Si la sélection de l'application est valide.
             if (isConfiguring)
             {
              ArrayList names;
              klist = new KetaiList(this, bt.getPairedDeviceNames());
              isConfiguring = false;
             }
             else
             {
             //Affichage de la reception des données.
              noFill();
              noStroke();
              textAlign(LEFT);
              text(info, 20, 104);
             }
            }
    
            //gauche
            public void Gauche(int theValue) { 
             //Envoi de données de la liaison Bluetooth.
              byte[] data = {'g','a','u','c','h','e','\r'};
              bt.broadcast(data);
             //Affichage de la reception des données.
              noFill();
              noStroke();
              textAlign(LEFT);
              text(info, 20, 104);
    
            }
            //droite
            public void Droite(int theValue) { 
             //Envoi de données de la liaison Bluetooth.
              byte[] data = {'d','r','o','i','t','e','\r'};
              bt.broadcast(data);
             //Affichage de la reception des données.
              noFill();
              noStroke();
              textAlign(LEFT);
              text(info, 20, 104);
    
            }
            //Arret urgence
            public void Arret(int theValue) { 
             //Envoi de données de la liaison Bluetooth.
              byte[] data = {'a','r','r','e','t','\r'};
              bt.broadcast(data);
             //Affichage de la reception des données.
              noFill();
              noStroke();
              textAlign(LEFT);
              text(info, 20, 104);
    
            }
    
            //Pause
            public void Pause(int theValue) { 
             //Envoi de données de la liaison Bluetooth.
              byte[] data = {'p','a','u','s','e','\r'};
              bt.broadcast(data);
    
             //Affichage de la reception des données.
              noFill();
              noStroke();
              textAlign(LEFT);
              text(info, 20, 104);
    
            }
    
            void keyPressed() {
    
            }
            public void console(int theValue){
    
            }
    
            void onKetaiListSelection(KetaiList klist) {
             String selection = klist.getSelection();
             bt.connectToDeviceByName(selection);
             //Présence d'une Liste.
             klist = null;
            }
    
    
            //Méthode de gestion des évenements (dans la librairie Ketai), permettant de //recevoir les données. 
            void onBluetoothDataEvent(String who, byte[] data) {
             if (isConfiguring)
             return;
             //Réception.
             info += new String(data);
             //Effacer si le mot trop long.
             if(info.length() > 150)
             info = "";
            }
    
            public void controlEvent(ControlEvent theEvent) {
              println(theEvent.getController().getName());
              n = 0;
            }
    

    Here is the code, and I would like the speed knob to be managed by a potentiometer, and the data sent by bluetooth, have you tracks?

  • Edit post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below....

    Kf

Sign In or Register to comment.