Loading...
Logo
Processing Forum
Hello,

i tried this code in Android Mode:
Copy code
  1. //import class to set up serial connection with wiring board
  2. import processing.serial.*;
  3. Serial port;
  4. //button setup
  5. color currentcolor;
  6. RectButton rect1, rect2;
  7. boolean locked = false;
  8. void setup() {
  9.   //set up window
  10.   size(200, 200);
  11.   color baseColor = color(102, 102, 102);
  12.   currentcolor = baseColor;
  13.   // List all the available serial ports in the output pane. 
  14.   // You will need to choose the port that the Wiring board is 
  15.   // connected to from this list. The first port in the list is 
  16.   // port #0 and the third port in the list is port #2. 
  17.   println(Serial.list()); 
  18.   // Open the port that the Wiring board is connected to (in this case 1
  19.   // which is the second open port in the array) 
  20.   // Make sure to open the port at the same speed Wiring is using (9600bps) 
  21.   port = new Serial(this, Serial.list()[2], 9600);
  22.   // Define and create rectangle button #1
  23.   int x = 30;
  24.   int y = 100;
  25.   int size = 50;
  26.   color buttoncolor = color(153, 102, 102);
  27.   color highlight = color(102, 51, 51); 
  28.   rect1 = new RectButton(x, y, size, buttoncolor, highlight);
  29.   // Define and create rectangle button #2
  30.   x = 90;
  31.   y = 100; 
  32.   size = 50;
  33.   buttoncolor = color(153, 153, 153);
  34.   highlight = color(102, 102, 102); 
  35.   rect2 = new RectButton(x, y, size, buttoncolor, highlight);
  36. }
  37. void draw() {
  38.   background(currentcolor);
  39.   stroke(255);
  40.   update(mouseX, mouseY);
  41.   rect1.display();
  42.   rect2.display();
  43. }
  44. void update(int x, int y) {
  45.   if(locked == false) {
  46.     rect1.update();
  47.     rect2.update();
  48.   } else {
  49.     locked = false;
  50.   }
  51.   //Turn LED on and off if buttons pressed where
  52.   //H = on (high) and L = off (low)
  53.   if(mousePressed) {
  54.     if(rect1.pressed()) {            //ON button
  55.       currentcolor = rect1.basecolor;
  56.       port.write('H');
  57.     } else if(rect2.pressed()) {    //OFF button
  58.       currentcolor = rect2.basecolor;
  59.       port.write('L');
  60.     }
  61.   }
  62. }
  63. class Button {
  64.   int x, y;
  65.   int size;
  66.   color basecolor, highlightcolor;
  67.   color currentcolor;
  68.   boolean over = false;
  69.   boolean pressed = false;   
  70.   void update() 
  71.   {
  72.     if(over()) {
  73.       currentcolor = highlightcolor;
  74.     } else {
  75.       currentcolor = basecolor;
  76.     }
  77.   }
  78.   boolean pressed() 
  79.   {
  80.     if(over) {
  81.       locked = true;
  82.       return true;
  83.     } else {
  84.       locked = false;
  85.       return false;
  86.     }    
  87.   }
  88.   boolean over() 
  89.   { 
  90.     return true; 
  91.   }
  92.   void display() 
  93.   { 
  94.   }
  95. }
  96. class RectButton extends Button {
  97.   RectButton(int ix, int iy, int isize, color icolor, color ihighlight) 
  98.   {
  99.     x = ix;
  100.     y = iy;
  101.     size = isize;
  102.     basecolor = icolor;
  103.     highlightcolor = ihighlight;
  104.     currentcolor = basecolor;
  105.   }
  106.   boolean over() 
  107.   {
  108.     if( overRect(x, y, size, size) ) {
  109.       over = true;
  110.       return true;
  111.     } else {
  112.       over = false;
  113.       return false;
  114.     }
  115.   }
  116.   void display() 
  117.   {
  118.     stroke(255);
  119.     fill(currentcolor);
  120.     rect(x, y, size, size);
  121.   }
  122. }
  123. boolean overRect(int x, int y, int width, int height) {
  124.   if (mouseX >= x && mouseX <= x+width && 
  125.       mouseY >= y && mouseY <= y+height) {
  126.     return true;
  127.   } else {
  128.     return false;
  129.   }
  130. }

Error: No library found for processing.serial

How can i add the serial library in Android Mode? I'd like to use bluetooth

Replies(13)

I'll say the same thing that I've said many times before: Android mode has no core libraries. Serial is a core library. The code base would be far too large to maintain across three modes. Instead, try using Ketai.
is there no other way?
As far as I know, there is no other way.
well, i saw the btserial library. But can not get the examples work :"Error from inside the Android tools, check the console"
Again, try Ketai. You're trying to access bluetooth; this is done differently than on a computer, and thus must us native Android calls. Ketai is built for Android, so it should work properly.
Are there any other examples fo ketai?
When i try the BluetoothCursor Example i get this error:

No library found for android.content
No library found for android.os
No library found for oscP5

Do these errors actually halt the build? If so:

The Android ones, android.content and android.os, mean that Processing can't find the Android core .jar file. Sometimes, this error won't actually cause a problem. If it, alone, halts the build, then there's something wrong with the way that your SDK is set up.

oscP5 is a library that you have to install separately. If you have the latest version of Processing, go to Sketch > Import Library > Add Library, and install oscP5.
"Error from inside android tools, check the console"

BUILD FAILED
C:\Programm\Android\android-sdk\tools\ant\build.xml:679: The following error occurred while executing this line:
C:\Programm\Android\android-sdk\tools\ant\build.xml:692: Compile failed; see the compiler error output for details.

I can not find oscP5
i installed it manually. it works, thanks!

Yes, you are going to get that error until you install oscP5. From the Library Manager, type "oscP5" into the search box at the bottom and it should show up.

EDIT: I see that you installed it manually... nevermind. I might have installed it manually, allowing me to see it the library manager in the first place...
i also didn't find it in the search box.

Now i'm looking for some example, like turn a led on, when touching a button on the phone.
Do you have any exampe code for sending and receiving bytes?
Look in the examples that come with oscP5. Personally, I don't have any experience with this library.