help required with changing arduino2max code


i posted this in the syntax and programs forum but on second thoughts maybe this is a better place to post it

i am trying to get six sensors chained together so they constantly loop and send their readings into maxmsp using the arduino2max code, as i discovered the other day that they cant all just ‘free run’ like i had them set originally as they give inaccurate readings

i have spent most of the day doing the rewiring as is detailed on the maxbotix site here :

but now i am having trouble with adapting the arduino2max code which is where my knowledge lets me down

it says on the page “you will have to “kick start” them, (at least 250mS or more after power is applied to the sensors to give the sensors this time to boot-up). To do this, pull the RX pin high on the first sensor for at least 20uS. Then the micro controller will have to return it’s pin to a high impedance state so that the next time around the TX output from the last sensor will make it’s way to the RX of the first sensor. Then all of the sensors in the chain will run in sequence.” but i am having trouble turning this in the required code

can anyone help me with writing this bit of code? as you see in the example i have tried to use the digital pin 12 to do the ‘kick starting’ but i just keep getting error messages and i get stuck

many thanks for any help in advance

int x = 0;                              // a place to hold pin values
int ledpin = 13;
int kickstart = 12;

void setup()
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  digitalWrite(12,HIGH);             /// this is the code i have managed so far but i am a bit stuck

void loop()

if (Serial.available() > 0){         // Check serial buffer for characters
    if ( == 'r') {       // If an 'r' is received then read the pins
for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);

for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    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


void sendValue (int x){              // function to send the pin value followed by a "space".
 Serial.print(32, BYTE);


Back to top