Combining Adafruit Trellis sketch and StandardFirmata Issue

I need assisting on combining the Adafruit Trellis sketch and standardfirmata sketch. I can successfully upload the two, but there is conflict with the serial readings.

Here is the Trellis Sketch:

/*************************************************** 
  This is a test example for the Adafruit Trellis w/HT16K33

  Designed specifically to work with the Adafruit Trellis 
  ----> https://www.adafruit.com/products/1616
  ----> https://www.adafruit.com/products/1611

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  MIT license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include "Adafruit_Trellis.h"

/*************************************************** 
  This example shows reading buttons and setting/clearing buttons in a loop
  "momentary" mode has the LED light up only when a button is pressed
  "latching" mode lets you turn the LED on/off when pressed

  Up to 8 matrices can be used but this example will show 4 or 1
 ****************************************************/

#define MOMENTARY 0
#define LATCHING 1
// set the mode here
#define MODE LATCHING 


Adafruit_Trellis matrix0 = Adafruit_Trellis();

// uncomment the below to add 3 more matrices
/*
Adafruit_Trellis matrix1 = Adafruit_Trellis();
Adafruit_Trellis matrix2 = Adafruit_Trellis();
Adafruit_Trellis matrix3 = Adafruit_Trellis();
// you can add another 4, up to 8
*/

// Just one
Adafruit_TrellisSet trellis =  Adafruit_TrellisSet(&matrix0);
// or use the below to select 4, up to 8 can be passed in
//Adafruit_TrellisSet trellis =  Adafruit_TrellisSet(&matrix0, &matrix1, &matrix2, &matrix3);

// set to however many you're working with here, up to 8
#define NUMTRELLIS 1

#define numKeys (NUMTRELLIS * 16)

// Connect Trellis Vin to 5V and Ground to ground.
// Connect the INT wire to pin #A2 (can change later!)
#define INTPIN A2
// Connect I2C SDA pin to your Arduino SDA line
// Connect I2C SCL pin to your Arduino SCL line
// All Trellises share the SDA, SCL and INT pin! 
// Even 8 tiles use only 3 wires max


void setup() {
  Serial.begin(9600);
  Serial.println("Trellis Demo");

  // INT pin requires a pullup
  pinMode(INTPIN, INPUT);
  digitalWrite(INTPIN, HIGH);
  
  // begin() with the addresses of each panel in order
  // I find it easiest if the addresses are in order
  trellis.begin(0x70);  // only one
  // trellis.begin(0x70, 0x71, 0x72, 0x73);  // or four!

  // light up all the LEDs in order
  for (uint8_t i=0; i<numKeys; i++) {
    trellis.setLED(i);
    trellis.writeDisplay();    
    delay(50);
  }
  // then turn them off
  for (uint8_t i=0; i<numKeys; i++) {
    trellis.clrLED(i);
    trellis.writeDisplay();    
    delay(50);
  }
}


void loop() {
  delay(30); // 30ms delay is required, dont remove me!
  
  if (MODE == MOMENTARY) {
    // If a button was just pressed or released...
    if (trellis.readSwitches()) {
      // go through every button
      for (uint8_t i=0; i<numKeys; i++) {
	// if it was pressed, turn it on
	if (trellis.justPressed(i)) {
	  Serial.print("v"); Serial.println(i);
	  trellis.setLED(i);
	} 
	// if it was released, turn it off
	if (trellis.justReleased(i)) {
	  Serial.print("^"); Serial.println(i);
	  trellis.clrLED(i);
	}
      }
      // tell the trellis to set the LEDs we requested
      trellis.writeDisplay();
    }
  }

  if (MODE == LATCHING) {
    // If a button was just pressed or released...
    if (trellis.readSwitches()) {
      // go through every button
      for (uint8_t i=0; i<numKeys; i++) {
        // if it was pressed...
	if (trellis.justPressed(i)) {
	  Serial.println(i);
	  // Alternate the LED
	  if (trellis.isLED(i))
	    trellis.clrLED(i);
	  else
	    trellis.setLED(i);
        } 
      }
      // tell the trellis to set the LEDs we requested
      trellis.writeDisplay();
    }
  }
}

I want to still be able to generate readings from the buttons pressed on the trellis and get the LED’s to light up.

If anyone can help me with this, that would be much appreciated

I can successfully upload the two, but there is conflict with the serial readings.

How can there be, when you can't upload both at the same time?

Do you want the Arduino to be stupid, running the StandardFirmata sketch? Or do you want it to be smart, running the Trellis sketch? In general, yes is the wrong answer. So it both.

Well I suppose it wasn't necessarily a 'successful' upload. But I combined the two sketches and corrected any errors, but this then stopped me gettin integer readings from the trellis.

I don't get what you mean. My knowledge with arduino is not advanced, am I more comfortable with MaxMSP. So I just want to upload a combined sketch in which I can read the messages from the adafruit trellis and still use other components such as IR sensors, potentiometers etc.

How would I go about getting these sketches to work in conjunction?

How would I go about getting these sketches to work in conjunction?

Do you have a clue how the PC communicates with the Arduino when the StandardFirmata sketch is loaded?

The PC sends encoded messages that the sketch understands, via the serial port. How are you encoding the message in a way that the sketch understands? How are you implementing that understanding?

Yes I get that, and when I tried to combine the sketches, I left out the 'serial.begin(9600)' from the trellis sketch. So they will both be running through serial rate of standardfirmata.

So Im assuming I need to set up some sort of variable lists, so that the serial monitor can display the messages from the different sketches as a list.

I have a basic understanding of doing sketches, just need to be pointed in the right direction

So Im assuming I need to set up some sort of variable lists, so that the serial monitor can display the messages from the different sketches as a list.

You don't seem to understand that you can only run one sketch at a time on the Arduino.

It makes no sense to "display the messages as a list" on the serial monitor.

In the StandardFirmata sketch, there is code to read and store the data from the serial port, and to parse, understand, and react to, the messages sent by the PC.

You will need to extend that understanding AND you'll need to implement the new code to react to AND you'll need to change the PC code to send different messages.

In order to do that, you need a thorough understanding of the code that sends the messages and you'll need to enhance that code FIRST.

What application is sending data now? What is that application supposed to send to the Arduino to make it deal with the Trellis thing (whatever that is)? Why does the sending application care about the Trellis?

I know I said that my knowledge is basic, but I not that basic. Of course I know that only one sketch can be ran at a time. That is why I am asking for help with combining the two sketches. When I said before that I uploaded the two sketches, I meant that I put them into one sketch, corrected any errors and uploaded that sketch; this then gave me conflict in the serial port.

What I want to know is, if I am trying to combines these two sketches into one sketch, How can I still get readings from both? As the trellis sketch requires serial readings to monitor when buttons are pressed, and obviously standardfirmata also needs to use the serial port.

Firstly I would just like to get data readings from a combined sketch within Arduino. The I will be using MaxMSP to receive the data readings of sensors, potentiometers, the trellis etc. to manipulate sound within a programmed patch. The Trellis is basically just a 4x4 multiplexing device that has LEDs and basically uses silicone cover to act as buttons that then light up etc.