Skip to content

Commit

Permalink
sensor sketch updated
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrake committed May 22, 2012
1 parent d248b86 commit 01db4b6
Showing 1 changed file with 53 additions and 19 deletions.
72 changes: 53 additions & 19 deletions examples/RemoteAlarm/Sensor/Sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Based on a sample implementation by Steve Evans (@tankslappa).

#include <JeeLib.h>
#include <avr/sleep.h>

#define LED_PIN 9 // activity LED, comment out to disable

Expand All @@ -16,42 +17,75 @@ const int PIN_REEDSWITCH2 = 5; // P2
byte outData, pending;
MilliTimer sendTimer;

ISR(WDT_vect) { Sleepy::watchdogEvent(); }

static void activityLed (byte on) {
#ifdef LED_PIN
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, !on);
#endif
// set reed switch pins to inputs and enable pullup
pinMode(PIN_REEDSWITCH1, INPUT);
pinMode(PIN_REEDSWITCH2, INPUT);
digitalWrite(PIN_REEDSWITCH1, HIGH);
digitalWrite(PIN_REEDSWITCH2, HIGH);
}

// setup function
void setup() {
Serial.begin(57600);
Serial.print("\n[BEC Remote Alarm Sensor Node]");
Serial.flush();
rf12_initialize('T', RF12_915MHZ);
}

void loop() {
rf12_recvDone();

if (sendTimer.poll(200)) {
++outData;
pending = 1;
}
// set reed switch pins to inputs and enable pullup
pinMode(PIN_REEDSWITCH1, INPUT);
pinMode(PIN_REEDSWITCH2, INPUT);
digitalWrite(PIN_REEDSWITCH1, HIGH);
digitalWrite(PIN_REEDSWITCH2, HIGH);
}

if (pending && rf12_canSend()) {
activityLed(1);
void debug_switch()
{
Serial.print("\ns1 = ");
Serial.print(digitalRead(PIN_REEDSWITCH1));
Serial.print(" s2 = ");
Serial.print(digitalRead(PIN_REEDSWITCH2));
rf12_sendStart(0, &outData, sizeof outData);
pending = 0;
delay(5);
activityLed(0);
}

bool check_switches()
{
return digitalRead(PIN_REEDSWITCH1) && digitalRead(PIN_REEDSWITCH2);
}

void send_payload()
{
rf12_sleep(RF12_WAKEUP);
while (!rf12_canSend())
rf12_recvDone();
bool switch_state = check_switches();
rf12_sendStart(0, &switch_state, sizeof switch_state);
rf12_sendWait(SLEEP_MODE_STANDBY);
rf12_sleep(RF12_SLEEP);
}

bool sent = false;

void loop() {
//Serial.print("loop\n");
//Serial.flush();
//activityLed(1);
//delay(50);
//activityLed(0);

if (!check_switches() && !sent) {
send_payload();
sent = true;
}

if (sendTimer.poll(30000)) {
sent = false;
//activityLed(1);
// debug_switch();
send_payload();
//activityLed(0);
}

Sleepy::loseSomeTime(10000);
}

0 comments on commit 01db4b6

Please sign in to comment.