#include <LedControl.h>
#include <SPI.h>
//#include <Ethernet.h>
const int MOTION_SENSOR_PIN = 7; // Arduino pin connected to the OUTPUT pin of motion sensor
const int BUZZER_PIN = 6; // Arduino pin connected to Buzzer's pin
int motionState = LOW; // current state of motion sensor's pin
int DIN = 11;
int CS = 10;
int CLK = 13;
//tinklo nustatymai-----------------------
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // physical mac address
//byte ip[] = { 158, 129, 41, 12 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
//byte gateway[] = { 158, 129, 41, 12 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; // subnet mask
// byte dns[] = {1 , 1, 1, 1}; // dns server
//EthernetServer server(443); // server port
//EthernetClient client;
//----------------------------------------
//const char url[] = "https://maker.ifttt.com/trigger/alarm-detected/with/key/oHEb99KNUlIlm4xqaE9i-s_lR82l1FMC05NF4NUzERS";
LedControl lc=LedControl(DIN,CLK,CS,1);
unsigned long start = 0;
int ijungta; //status
float sinVal; //buzzer
int toneVal; //------
bool alarmON = false;
void setup() {
ijungta=0;
Serial.begin(9600); // initialize serial
//Ethernet.begin(mac);
pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode
pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode
lc.shutdown(0,false); //The MAX72XX is in power-saving mode on startup
lc.setIntensity(0,14); // Set the brightness to maximum value
lc.clearDisplay(0);
digitalWrite(BUZZER_PIN, LOW);
}
void loop() {
if(ijungta==1){ //ijungtas alarmas
motionState = digitalRead(MOTION_SENSOR_PIN); // read new state
if (motionState == LOW) { // pin state: nera judesio
lc.clearDisplay(0);
digitalWrite(BUZZER_PIN, LOW); // turn off
}
else if (motionState == HIGH) { // pin state change: HIGH -> LOW
Serial.println("detected");
while(ijungta == 1){
start = millis();
if(ijungta==0){
//resetFunc(); //reset arduino
}
if(start>=5000){
AlarmSensors();
if(!alarmON){
Serial.println("alarm ONCE");
alarmON = true;
}
}
}
}
}
else if(ijungta==0){
motionState = 0;
//resetFunc(); //reset arduino
}
//delay(5000);
//ijungta = 1;
}
//void(* resetFunc) (void) = 0;
void AlarmEmail(){
//Ethernet.begin(mac, ip, dns);
//delay(1000);
//client.connect(server, 443);
//delay(1000);
//client.stop();
}
void AlarmSensors(){
tone(BUZZER_PIN, 600);
TurnOnRightLeds();
TurnOnLeftLeds();
delay(250);
lc.clearDisplay(0);
delay(250);
tone(BUZZER_PIN, 0);
delay(200);
tone(BUZZER_PIN, 600);
TurnOnRightLeds();
TurnOnLeftLeds();
delay(250);
lc.clearDisplay(0);
delay(250);
tone(BUZZER_PIN, 0);
delay(200);
}
void TurnOnRightLeds(){
for(int i=0; i<8;i++)
{
lc.setLed(0,0,i,true);
lc.setLed(0,1,i,true);
lc.setLed(0,2,i,true);
lc.setLed(0,3,i,true);
}
}
void TurnOnLeftLeds(){
for(int i=0; i<8;i++)
{
lc.setLed(0,4,i,true);
lc.setLed(0,5,i,true);
lc.setLed(0,6,i,true);
lc.setLed(0,7,i,true);
}
}