Processing.serial in BlueJ doesn't work

@Paul94 I was able to get the arduino_example sketch running in BlueJ after some tinkering. Did this with a Macbook Pro and an Adafruit FLORA running the StandardFirmata Arduino sketch.

I exported the slightly modified flora_blink sketch from Processing as @kfrajer suggested, then copied the Java folder from that package to a convenient location on my filesystem. In BlueJ, I added all of the .jar files except for flora_blink.jar before restarting the IDE. The code below enables me to click a square and blink the FLORA’s onboard LED.

import processing.core.PApplet;
import processing.serial.*;
import cc.arduino.*;

public class P5 extends PApplet
{
    Arduino arduino;

    int off = color(4, 79, 111);
    int on = color(84, 145, 158);

    int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
 Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };

    public static void main(String[] args)
    {
        PApplet.main("P5");
    }
    
    public void settings()
    {
        size(470, 200);
    }
    
    public void setup()
    {
        arduino = new Arduino(this, "/dev/cu.usbmodem1411", 57600);
    }
    
    public void draw()
    {
        background(off);
        stroke(on);
  
        for (int i = 0; i <= 13; i++) {
            if (values[i] == Arduino.HIGH)
                fill(on);
            else
                fill(off);
      
            rect(420 - i * 30, 30, 20, 20);
        }
    }
    
    public void mousePressed()
    {
        int pin = (450 - mouseX) / 30;
  
        // Toggle the pin corresponding to the clicked square.
        if (values[pin] == Arduino.LOW) {
            arduino.digitalWrite(pin, Arduino.HIGH);
            values[pin] = Arduino.HIGH;
         } else {
             arduino.digitalWrite(pin, Arduino.LOW);
             values[pin] = Arduino.LOW;
         }
     }
}

flora_blink

1 Like