Read and utilize serial array from Arduino
in
Integration and Hardware
•
10 months ago
Hi all,
I have 4 pressButtons on my Arduino that are sending serial signal when they are on or off.
I need to have the 4 different signals doing 4 different things on processing (e.g. change background color).
So far I can send the signal properly from Arduino to Processing, but I can't wrap my mind around how to use those signals to do different things in processing.
I tried to see if there were other threads on this topic but I couldn't find one (if there are, please post the link)
Any help would be very much appeciated!
Thank you all so much in advance!
BTW: the basic sketch for processing is this:
- // Example by Tom Igoe
- import processing.serial.*;
- Serial myPort; // The serial port
- void setup() {
- // List all the available serial ports
- println(Serial.list());
- // I know that the first port in the serial list on my mac
- // is always my Keyspan adaptor, so I open Serial.list()[0].
- // Open whatever port is the one you're using.
- myPort = new Serial(this, Serial.list()[0], 9600);
- }
- void draw() {
- // Expand array size to the number of bytes you expect
- byte[] inBuffer = new byte[5];
- while (myPort.available() > 0) {
- inBuffer = myPort.readBytes();
- myPort.readBytes(inBuffer);
- if (inBuffer != null) {
- String myString = new String(inBuffer);
- println(myString);
- }
- }
- }
1