BlinkM + PIR

I got it working, just took me a while...

Actually did a BlinkM with 2x PIR's each sending different singles to BlinkM

The project is going to be each room in my house will affect the BlinkM differently... so while i'm in bed if the light turns red, i know it's detected movement in the red room.... Which will be the living room, Blue for my hallway... so i know where people are in my house at all times...

Code here.

#include "Wire.h"
#include "BlinkM_funcs.h"

#define blinkm_addr 0x00
int delay_time = 500; // time betwen colors, 1000 milliseconds = 1 second
int calibrationTime = 30;
byte r,g,b;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 3; //the digital pin connected to the PIR sensor's output PIR 1
int pirPin2 = 2;

/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(pirPin2, INPUT);
digitalWrite(pirPin, LOW);
digitalWrite(pirPin2, LOW);

//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR'S ACTIVE");
delay(50);
BlinkM_beginWithPower();
BlinkM_stopScript( blinkm_addr ); // turn off startup script
}

////////////////////////////
//LOOP
void loop(){

if(digitalRead(pirPin2) == HIGH){
BlinkM_setRGB (blinkm_addr, 0x00,0x00,0xff );
delay(delay_time);
BlinkM_setRGB (blinkm_addr, 0xff,0xff,0xff );
delay(delay_time);
BlinkM_setRGB (blinkm_addr, 0x00,0x00,0xff );
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected on sensor 2 at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}

if(digitalRead(pirPin2) == LOW){

if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended on sensor 2 at "); //output
BlinkM_setRGB (blinkm_addr, 0x00,0x00,0x00 );
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);

}}

if(digitalRead(pirPin) == HIGH){
BlinkM_setRGB (blinkm_addr, 0xff,0x00,0x00 );
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected on sensor 1 at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}

if(digitalRead(pirPin) == LOW){

if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended on sensor 1 at "); //output
BlinkM_setRGB (blinkm_addr, 0x00,0x00,0x00 );
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}