Serial.println(); // Send a carriage returnt to mark end of pin data. delay (5); // add a delay to prevent crashing/overloading of the serial port

}//end of if (serialvalue == 'r')

/*------------------------Here we receive the numbers sent from the Max digitalOuts------------------- The digital writes and reads here are meant only as examples. You can replace what is in these and expand this whole section to deal with more incoming numbers. You can use any number from 0-255 except 114, since that is the ASCII code for 'r' and is used above Be sure any pin you use here is declared in setup() as an OUTPUT and that you're not reading from it just above this section.*/

if (Serial.available()) { // read the most recent byte (which will be from 0 to 255): brightness = Serial.read(); // set the brightness of the LED: analogWrite(ledPin, brightness); } //--------------------------End of receiving numbers---------------------------------

I don't really know, I just ripped that code out of the example that comes with Max2Arduino. I've barely used Arduino before. I have my sensor built and it is being read into Max just fine (cheers for the tip about inverting values though). I want to use Analog Write instead of the Digital Out stuff, to feed values back from the Max Patch back into the sensors.

I'm still stuck getting Analog Write to work. If I use the 'serial out' part of the patch in isolation it works with Arduino and I can use a Max slider to fade an LED. I believe the example tutorial is called Dimmer. I am essentially trying to integrate this into my project.

I have a sensor that feeds data in to Max from the Arduino this data then needs to be transmitted back to the Arduino in a feedback loop so I can modulate the voltage coming from the sensor (I will run PWM through a LPF to convert to analog voltage once I have it working properly). So I need to use Analog Write on PWM outs. But this isn't working. I have an LED attached to pin 9 then to ground and it is not dimming.

Can someone please help me with the code, I have no idea what I'm doing! :~