
#include "LedControl.h"
#include <RCSwitch.h>

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to LOAD(CS)
 pin 10 is connected to the CLK 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,10,11,1);



int buzzer = 13;
const int d1=105;
const int d2=d1*3;
const int d3=700;

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(115200);
  Serial.println("Waiting");
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
   pinMode(buzzer,OUTPUT);

    lc.shutdown(0,false);
  /* Set the brightness to a low value */
  lc.setIntensity(0,0);//8 auf 4 geändert
  /* and clear the display */
  lc.clearDisplay(0);
}
void dotMessage(){
 byte r[8]={ B01111110,
             B01100010,
             B01010010,
             B01001010,
             B01001010,
             B01010010,
             B01100010,
             B01111110};
             
  lc.setRow(0,0,r[0]);
  lc.setRow(0,1,r[1]);
  lc.setRow(0,2,r[2]);
  lc.setRow(0,3,r[3]);
  lc.setRow(0,4,r[4]);
  lc.setRow(0,5,r[5]);
  lc.setRow(0,6,r[6]);
  lc.setRow(0,7,r[7]);
  delay(600);
  lc.clearDisplay(0);
  delay(600);
  lc.setRow(0,0,r[0]);
  lc.setRow(0,1,r[1]);
  lc.setRow(0,2,r[2]);
  lc.setRow(0,3,r[3]);
  lc.setRow(0,4,r[4]);
  lc.setRow(0,5,r[5]);
  lc.setRow(0,6,r[6]);
  lc.setRow(0,7,r[7]);

  delay(600);
}
//mail in post box found
void SMS(){
 
    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);
    
    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);

    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);


    delay(d2-d1);
    

    digitalWrite(buzzer,HIGH);
    delay(d2);
    digitalWrite(buzzer,LOW);
    delay(d1);

    digitalWrite(buzzer,HIGH);
    delay(d2);
    digitalWrite(buzzer,LOW);
    delay(d1);
    
    delay(d2-d1);
    
    digitalWrite(buzzer,HIGH);
    delay(d1);//wait for 1ms
    digitalWrite(buzzer,LOW);
    delay(d1);
    
    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);

    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);
    
      
}
//No mail found
void ok(){


byte r[8]={  B10000001,
             B01000010,
             B00100100,
             B00011000,
             B00011000,
             B00100100,
             B01000010,
             B10000001};
             
  lc.setRow(0,0,r[0]);
  lc.setRow(0,1,r[1]);
  lc.setRow(0,2,r[2]);
  lc.setRow(0,3,r[3]);
  lc.setRow(0,4,r[4]);
  lc.setRow(0,5,r[5]);
  lc.setRow(0,6,r[6]);
  lc.setRow(0,7,r[7]);
  delay(600);
  lc.clearDisplay(0);
  delay(600);
  lc.setRow(0,0,r[0]);
  lc.setRow(0,1,r[1]);
  lc.setRow(0,2,r[2]);
  lc.setRow(0,3,r[3]);
  lc.setRow(0,4,r[4]);
  lc.setRow(0,5,r[5]);
  lc.setRow(0,6,r[6]);
  lc.setRow(0,7,r[7]);

  delay(600);
lc.clearDisplay(0);
  
}

void loop() {
  delay(10);
  if (mySwitch.available()) {
    long RecLux=mySwitch.getReceivedValue();
    Serial.println( RecLux);
     delay(150);
     mySwitch.resetAvailable();


   
    
    if (RecLux>400){
    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);
    
    digitalWrite(buzzer,HIGH);
    delay(d1);
    digitalWrite(buzzer,LOW);
    delay(d1);
    lc.clearDisplay(0);
    delay(10);
   ok();
   
  }
  

else if(RecLux<399){
  
delay(50);
dotMessage();


  delay(10);
  SMS();
  delay(10);
  
  }
  
  }

}
