Question regarding Sensor stream!

So I found this code earlier:

int SensorPins[3] = {0, 1, 2}; // Array to hold pin numbers of sensors
// fill with first 3 analog pins as default
// **NOTE: Change these numbers if using other pins

int SensorPrevVals[3] = {0, 0, 0}; // Array to hold previous sensor values
// fill with default value of 0

int Val = 0; // Variable for current value read from sensor pin
int NewVal = 0; // Variable for averaged sensor value ((current + previous) / 2)
int i = 0; // Variable for index for for-loop
int inByte = 0; // Variable for incoming serial data

void setup()

void loop()
if(Serial.available()>0) // Is there data waiting in the serial port?
{ // If so, proceed with code block, otherwise don't
inByte =; // Read data from serial buffer and store in variable (to get rid of it)

for(i = 0; i < 3; i = i + 1){
Val = analogRead(SensorPins[i]); // Read sensor value and store in Val
NewVal = (Val + SensorPrevVals[i]) / 2; // Average current and previous values for smoothing
SensorPrevVals[i] = Val; // Store current Val as PrevVal for next time
sendBinary(NewVal); // Break NewVal into low & high bytes and send out
Serial.println(); // Send CR & LF (ASCII 13 & 10) to mark end of message

// function to send the given integer value to the serial port as two bytes
void sendBinary(int value)
// send the two bytes that comprise an integer
Serial.write(lowByte(value)); // send the low byte
Serial.write(highByte(value)); // send the high byte

Which allows me to receive analog input values in MaxMSP as separate values. I am just wondering if it is possible to add 12C values to this code in order to again receive the messages in MaxMSP. I have some SRF02 ultrasonic sensors that I want to use, and using this code will allow my max patch to run smoother. Also can I add some digital reads to the serial print?

Any advice would be great

Do you mean using I2C (Wire library) instead of Serial? Or what do you want to know?

What's "MaxMSP"?

What I want to do is read 4 srf02 ultrasonic sensors using 12C and incorporate this into the sketch above. So I want to be able to use this sketch to read general analog inputs and also read the 12C sensors. Any advice?

I see no special problems. Follow the instructions for programming the slave addresses, before using multiple sensors on one bus.

Yes I have programmed the slave addresses. I'm just wondering how I would go about putting this into this sketches, as at the moment it is only built for analog inputs.

See the Wire library examples.