AWOL:
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <IRremote.h>
#include <VirtualWire.h>
const int TX_DIO_Pin = 4;
int allarm;
float vers = 0.07;
int funct[5] = {11, 12, 13, 14, 19};
int a = 0;
int input_pin = 3; //set D10 as input signal pin
IRrecv irrecv(input_pin);
decode_results signals;
void setup()
{
Serial.begin(9600);
Serial.println("Home made Allarm System");
Serial.println("Made by Alessandro Rosmo");
delay(300);
Serial.print("Version: ");
Serial.println(vers);
delay(300);
Serial.println("Funzioni: ");
delay(100);
Serial.println("11 = Allarme On // 12 = Presenza rilevata");
Serial.println("13 = Segnale di spegnimento // 14 = Presenza rilevata ma sensore disattivato");
Serial.println("19 = Carattere di controllo");
Serial.println("5 secondi di attesa per la corretta inizializzazione del sistema");
delay(5000);
irrecv.enableIRIn();
delay(100);
allarm = !allarm;
initialize_transmitter();
delay(100);
transmit_integer(funct[0]);
delay(100);
Serial.println("Entro in sleep mode dal setup");
delay(1000);
attachInterrupt(0, vuota, CHANGE);
attachInterrupt(1, vuota, CHANGE);
sleep();
}
void sleep()
{
Serial.println("SLEEP");
delay(200);
attachInterrupt(0, vuota, CHANGE);
attachInterrupt(1, vuota, CHANGE);
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu ();
}
void initialize_transmitter() {
vw_set_tx_pin(TX_DIO_Pin);
vw_set_ptt_inverted(true);
vw_setup(2000); // Bits per sec
}
void transmit_integer(unsigned int Data) {
Serial.println("FUNZIONE TRANSMIT_INTEGER");
byte TxBuffer[2];
Serial.println("1");
TxBuffer[0] = Data >> 8;
Serial.println("2");
TxBuffer[1] = Data;
Serial.println("3");
vw_send((byte *)TxBuffer, 2);
Serial.println("4");
vw_wait_tx();
Serial.println("5");
Serial.println("FINE FUNZIONE TRANSMIT_INTEGER");
}
void vuota()
{
}
void loop() {
int i = digitalRead(2);
detachInterrupt(0);
detachInterrupt(1);
if (irrecv.decode(&signals)) {
String received = String(signals.value, HEX);
Serial.println(received);
if (received == "ffa25d") {
allarm = !allarm;
if (allarm)
{
Serial.println("ALLARME ON");
transmit_integer(funct[0]);
}
else
{
Serial.println("ALLARME OFF");
transmit_integer(funct[2]);
}
}
delay(300);
irrecv.resume();
sleep();
}
if (i == 1) {
if (allarm)
{
Serial.println("PRESENZA RILEVATA!!!!!!!!!");
delay(10000);
transmit_integer(funct[1]);
}
else
{
Serial.println("Presenza rilevata ma allarme disattivato");
delay(10000);
transmit_integer(funct[3]);
}
sleep();
}
}
I apologize if i did something wrong..next time i'll use
the "code" syntax to post my code, sorry..
Thanks..
Still looking for some answer..