//#include <PCM.h>

#define RLR  2                              // de relays ledpaneel
#define RLG  3 
#define RLB  4 
#define RB   5                              // de realy voor netspanning bulb
                                            // in de void loop gaat de bulb ong. 30x aan/uit
#define RS   6                              // de relay voor de speaker (vanwege tikken)

#define echoPin 8                           // de ultrasonicsensor
#define trigPin 9

//#sample pin 11                           // het geluid

long duration, distance;                    // wederom ultrasonicsensor

                                            // de samples
                                            // 1ste handen wassen
                                            // 2de dank u wel

const unsigned char sample1[] PROGMEM = { 
};
const unsigned char sample2[] PROGMEM = {
};

void setup()
{    

Serial.begin(9600);
  pinMode(RLR, OUTPUT);                         // relays
  pinMode(RLG, OUTPUT);
  pinMode(RLB, OUTPUT);
  pinMode(RB, OUTPUT);
  pinMode(RS, OUTPUT);

  pinMode(echoPin,INPUT);                       // ultrasonic
  pinMode(trigPin,OUTPUT);  

digitalWrite(RS,1);
 delay(300); 
  //startPlayback(sample1, sizeof(sample1));
for (int i = 0; i < 1; i++) {PAT_AAN();} 
delay(2000);
digitalWrite(RS,0);
delay(200);
}

  void loop()

{
  digitalWrite(trigPin,LOW);                    // ultrasonic meet de afstand
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  duration = pulseIn(echoPin, HIGH);

  distance = duration*0.034/2;
  Serial.println(distance);
  delay(200);
  for (int i = 0; i < 1; i++) {PAT_UIT();} 
  delay(200);

if (distance<=30)                              // als de afstand kleiner is dan ...
                                                // dit duurt ong. 10 minuten
                                                // 20 seconden actief en 2 minuten passief lichtshow 
{

Serial.println ("IEMAND STAAT ERVOOR, SAMPLE WORDT AFGESPEELD EN 2 á 3 MINUTEN LICHTSHOW");
 digitalWrite(RS,1);
 delay(300); 
  //startPlayback(sample1, sizeof(sample1));
for (int i = 0; i < 1; i++) {PAT_AAN();} 
delay(2000);
digitalWrite(RS,0);
delay(100);
for (int i = 0; i < 1; i++) {PAT_UIT();} 
delay(200);
Serial.println ("ACTIEVE LICHTHSHOW");
   Serial.println ("patroon 1");
for (int i = 0; i < 3; i++) {PAT1();}
      Serial.println ("patroon 2");
for (int i = 0; i < 1; i++) {PAT2();}
      Serial.println ("patroon 3");
for (int i = 0; i < 2; i++) {PAT3();}
   Serial.println ("patroon 4");
for (int i = 0; i < 2; i++) {PAT4();}
   Serial.println ("patroon 1");
for (int i = 0; i < 3; i++) {PAT1();}
Serial.println ("PASSIEVE LICHTSHOW");
for (int i = 0; i < 1; i++) {PAT_UIT();} 
delay(1000);
   Serial.println ("patroon 5");
for (int i = 0; i < 2; i++) {PAT5();}
Serial.println ("PASSIEVE LICHTSHOW EN DE BULB DOET NIET MEER MEE");
   Serial.println ("patroon 6");
for (int i = 0; i < 4; i++) {PAT6();}
   Serial.println ("patroon 7");
for (int i = 0; i < 4; i++) {PAT7();}
   Serial.println ("patroon 1");
for (int i = 0; i < 3; i++) {PAT1();}
Serial.println ("KLAAR ERMEE NU PAUZE VOOR 8 MINUTEN");
delay(420000);                                                 // de pauze
}
}


// DE PATRONEN

void PAT_AAN() {                      // ALLES AAN
   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
}
void PAT_UIT() {                      // ALLES UIT
   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);
}
void PAT1() {                      // AAN of UIT ALLES KNIPPERENT
   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(300);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);
   delay(300);
}
void PAT2() {                      // BULB KNIPPEREND MET VERANDERD LEDPANEEL
    digitalWrite(RLR,1);          
    digitalWrite(RLG,0);
    digitalWrite(RLB,0);          
   for (int i = 0; i < 2; i++){
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
   }
    digitalWrite(RLR,0);          
    digitalWrite(RLG,1);
    digitalWrite(RLB,0);          
   for (int i = 0; i < 2; i++){
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
   }
    digitalWrite(RLR,0);          
    digitalWrite(RLG,0);
    digitalWrite(RLB,1);          
   for (int i = 0; i < 2; i++){
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
   }
    digitalWrite(RLR,0);          
    digitalWrite(RLG,1);
    digitalWrite(RLB,0);          
   for (int i = 0; i < 2; i++){
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
   }
    digitalWrite(RLR,1);          
    digitalWrite(RLG,0);
    digitalWrite(RLB,0);          
   for (int i = 0; i < 2; i++){
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
   }
   for (int i = 0; i < 2; i++){
    digitalWrite(RLR,1);          
    digitalWrite(RLG,1);
    digitalWrite(RLB,1);          
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
    digitalWrite(RLR,0);          
    digitalWrite(RLG,0);
    digitalWrite(RLB,0);          
    digitalWrite(RB,1);
    delay(150);
    digitalWrite(RB,0);
    delay(150);
}
}
void PAT3() {                      // BULB AAN LEDPANEEL GAAT KLEUREN LANGS
   for (int i = 0; i < 2; i++){ 
   digitalWrite(RLR,1);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(150);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(150);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(150);
   }
  for (int i = 0; i < 2; i++){  
   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(225);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(225);
  }
   digitalWrite(RB,0);
}
void PAT4() {                      // PAT3 MAAR DAN ANDERSOM QUA LEDPANEEL
   for (int i = 0; i < 2; i++){ 
   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(150);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(150);

   digitalWrite(RLR,1);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(150);
   }
  for (int i = 0; i < 2; i++){  
   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(225);

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(225);
  }
   digitalWrite(RB,0);
}
void PAT5() {                      // AAN of UIT ALLES KNIPPERENT
   digitalWrite(RLR,1);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(random(150, 300));
   digitalWrite(RB,0);

   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,0);          
   digitalWrite(RB,1);
   delay(random(150, 300));
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(random(150, 300));
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,1);
   delay(random(150, 300));
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

}
void PAT6() {                      // AAN of UIT ALLES KNIPPERENT
   digitalWrite(RLR,1);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);

   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,1);          
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

   digitalWrite(RLR,1);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,1);          
   digitalWrite(RB,0);
   
   delay(random(2000, 5000));

}
void PAT7() {                      // AAN of UIT ALLES KNIPPERENT
   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);

   delay(random(2000, 5000));

   digitalWrite(RLR,1);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);
   
   delay(random(100, 200));
   
   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);

   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,1);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);
   
   delay(random(100, 200));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,0);          
   digitalWrite(RB,0);

   delay(random(2000, 5000));

   digitalWrite(RLR,0);          
   digitalWrite(RLG,0);
   digitalWrite(RLB,1);          
   digitalWrite(RB,0);
   
   delay(random(100, 200));
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
NOCOMNCVCCGNDINLED1PWRRelay Module
relay1:VCC
relay1:GND
relay1:IN
relay1:NC
relay1:COM
relay1:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay3:VCC
relay3:GND
relay3:IN
relay3:NC
relay3:COM
relay3:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay4:VCC
relay4:GND
relay4:IN
relay4:NC
relay4:COM
relay4:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay5:VCC
relay5:GND
relay5:IN
relay5:NC
relay5:COM
relay5:NO
NOCOMNCVCCGNDINLED1PWRRelay Module
relay6:VCC
relay6:GND
relay6:IN
relay6:NC
relay6:COM
relay6:NO
ultrasonic1:VCC
ultrasonic1:TRIG
ultrasonic1:ECHO
ultrasonic1:GND
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2