please help - merging 2 pieces of code


hi there

i hope can please me

i have 2 pieces of code , need merge them , bit stuck.

the first bit of code arduino2max code has been changed little reads values 6 distance sensors on wall chained repeatedly reads values sensors in loop , sends them arduino analogue pins

i trying incorporate code pir sensor connected digital pin when pir sensor detects motion turns on sound in max msp , if no motion detected turns sound off.  

hopefully solve problem having distance sensors give false readings when no 1 present , therefore make unwanted sounds

this arduino2max code :
code: [select]
int x = 0;                              // place hold pin values
int ledpin = 13;


void setup()
{
 serial.begin(115200);               // 115200 default arduino bluetooth speed
 digitalwrite(13,high);              ///startup blink
 delay(600);
 digitalwrite(13,low);
 pinmode(13,input);

 delay(500);
 digitalwrite(12,high);              // part code send first pin in                                      
 delay(20);                               //  chain high sensors give continuous reading                                        
 digitalwrite(12,low);            //    one after other          
 pinmode(12, input);    
 }    
         
                                 
                                         



void loop()
{

if (serial.available() > 0){         // check serial buffer characters
       
   if (serial.read() == 'r') {       // if 'r' received read pins
   
   for (int pin= 0; pin<=5; pin++){      // read , send analog pins 0-5
   x = analogread(pin);
   sendvalue (x);
   }

   for (int pin= 2; pin<=13; pin++){     // read , send digital pins 2-13
   x = digitalread(pin);
   sendvalue (x);
   }
 
   serial.println();                 // send carriage returnt mark end of pin data.
   delay (5);                        // add delay prevent crashing/overloading of serial port
 
 }

}
}

void sendvalue (int x){              // function send pin value followed "space".
serial.print(x);
serial.print(32, byte);
}






and pir sensor code, elsewhere on site
code: [select]
int ledpin = 13; // led connected control pin 13
int pirsensor = 2; // pir sensor plugged @ digital pin 2
int state = 0; // variable store value read sensor pin
int statepin = low; // variable used store last led status, toggle light

void setup() {
pinmode(ledpin, output); // declare ledpin as output
pinmode(pirsensor, input); // declare pirsensor as output
serial.begin(9600); // use serial port
}

void loop() {
state = digitalread(pirsensor); // read sensor , store in "state"

if (state != 0)
{
digitalwrite(led1, high);
serial.println("motion detected!"); // send string "motion detected!" // computer
}
else
digitalwrite(led1, low); // turns light off if motion not detected

delay(100); // have make delay avoid overloading serial port
}


i hope clear , can me out desperately trying sorted out impending show

many in advance advice

:)

please not crosspost.

- brian


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > please help - merging 2 pieces of code


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums