Hello there,
I’m very new to Processing, so forgive me if this is an overly simple question or whatever.
I have created a Toggle button that I’m using to toggle an LED on/off on an Arduino. In the code below, when the “Test_LEDs” button is toggled, either “T” or “F” is written to the serial port. My Arduino code reads this byte and does the appropriate action.
The code works perfectly fine, but I’d like to use a longer string instead of “T” or “F”, e.g. “LED ON” or “LED OFF”, simply because I want to add more buttons to this GUI and long strings will be easier for me to understand what each button does.
When I try to add a longer string, e.g. port.write('LED ON')
I get the error message “Invalid character constant”. Is there a way to print a whole string to the serial port instead of just one letter?
Here is my code:
// MAX7221 array GUI for Arduino
import controlP5.*; //import ControlP5 library
import processing.serial.*;
Serial port;
ControlP5 cp5; //create ControlP5 object
PFont font;
void setup(){
size(300, 450); //window size, (width, height)
smooth();
port = new Serial(this, "COM4", 9600); // Setup Serial port - enter appropriate COM port
cp5 = new ControlP5(this);
// create a toggle for Test Array function
cp5.addToggle("Test_LEDs")
.setPosition(40,100)
.setSize(50,50)
;
}
void draw(){ // Loop to draw the GUI
background(0, 0 , 0); // background color of window (r, g, b) or (0 to 255
}
void Test_LEDs(boolean Test_LEDs) {
if(Test_LEDs == true) {
println("Test LEDs ON");
port.write('LED');
} else {
println("Test LEDs OFF");
port.write('F');
}
}