Processing bluetooth android with a slider control.

edited January 2016 in Android Mode

Hi, I have a project on processing bluetooth android ( version221 ) with a slider control. But The conversion method intToByteArray () does not work in void COMMANDE (Slider).

Processing code is:

import android.content.Intent; import android.os.Bundle; import ketai.net.bluetooth.*; import ketai.ui.*; import ketai.net.*;

import controlP5.*; // Importe la librairie GUI controlP5

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;

ControlP5 controlP5; // déclare un objet principal de la librairiecontrolP5

Button boutton; Slider slider; int valeur; byte [] a; byte [] b;

//******************************************************************** //Liaison Bluetooth //********************************************************************

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); frameRate(10); orientation(PORTRAIT); background(0);

//Début de connexion Bluetooth. bt.start(); //Sélection de l'application. isConfiguring = true; //Couleur de fond fontMy = createFont("SansSerif", 40); textFont(fontMy);

controlP5 = new ControlP5(this); // Initialise l'objet principal de la librairie controlP5.

boutton = controlP5.addButton("BOUTON",0,150,525,200,100);

slider = controlP5.addSlider("COMMANDE",0,255,127,20,50,360,30); // ajoute un Slider au ControlP5 slider.setNumberOfTickMarks(256); slider.showTickMarks(false); slider.setDecimalPrecision(0);

}

void draw() { //Si la sélection de l'application est valide. if (isConfiguring) { klist = new KetaiList(this, bt.getPairedDeviceNames()); isConfiguring = false; } else { background(0,50,0); } //Affichage de la reception des données. fill(204); noStroke(); textAlign(LEFT); text(info, 20, 104); }

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 = ""; }

void BOUTON() { // fonction évènement Button de meme nom - reçoit la valeur byte[] data = {'v','\n'}; bt.broadcast(data); bReleased = false; println(data); }

void COMMANDE( int valeur) { // fonction évènement Slider de meme nom - reçoit la valeur

byte[] a= intToByteArray(valeur); // excellent function for converting int to byte array (byte[]) which is what the Ketai bluetooth
//library sends. byte[] b={'q'}; // sending the 'q' character as a byte[] bt.broadcast(b); // send identifier character bt.broadcast(a); // send (broadcast) the bluetooth slider info

println("Evènement Slider PWM avec valeur = "+valeur); // message console Processing - debug

delay(10); // entre 2 prises en compte }

Processing android tells me the following error: The method intToByteArray(int) is undefined for the type

Does anyone have an idea to help me? Thanks.

Answers

  • @fweiss=== please format your code...

  • Hello, why this method intToByteArray() is not active Android then it function in java?

  • @fweiss=== it s difficult to help you with this unformatted code; yet: what is this intToByteArray method??? is it waiting an int? -probably that your slider sends values as float...

Sign In or Register to comment.