Skip to content

Instantly share code, notes, and snippets.

@jamescw
Created September 19, 2011 23:16
Show Gist options
  • Save jamescw/1227875 to your computer and use it in GitHub Desktop.
Save jamescw/1227875 to your computer and use it in GitHub Desktop.
/* JeeNode / JeeNode USB / JeeSMD
-------|-----------------------|----|-----------------------|----
| |D3 A1 [Port2] D5 | |D3 A0 [port1] D4 | |
|-------|IRQ AIO +3V GND DIO PWR| |IRQ AIO +3V GND DIO PWR| |
| D1|TXD| ---- ---- |
| A5|SCL| D12|MISO|+3v | |
| A4|SDA| Atmel Atmega 328 D13|SCK |MOSI|D11 |
| |PWR| JeeNode / JeeNode USB / JeeSMD |RST |GND | |
| |GND| D8 |BO |B1 |D9 |
| D0|RXD| ---- ---- |
|-------|PWR DIO GND +3V AIO IRQ| |PWR DIO GND +3V AIO IRQ| |
| | D6 [Port3] A2 D3 | | D7 [Port4] A3 D3 | |
-------|-----------------------|----|-----------------------|----
*/
#include <Ports.h>
#include <RF12.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
Port lock (1);
Port ledRed (3);
Port ledGreen (4);
Port blank (2);
byte radioOn;
EMPTY_INTERRUPT(WDT_vect);
void setup() {
Serial.begin(57600);
rf12_config();
rf12_easyInit(0); // set up easy transmissions at maximum rate
lock.mode(INPUT);
lock.digiWrite(1); //Pull-up on
ledGreen.mode(OUTPUT);
ledRed.mode(OUTPUT);
radioOn = 0;
}
void loop() {
Serial.println("Start");
Serial.print("Radio: ");
Serial.println(radioOn? "ON" : "OFF");
if (radioOn && rf12_easyPoll() == 0) {
Serial.println("Sleeping radio");
rf12_sleep(0);
radioOn = 0;
}
if(!radioOn) {
Serial.println("Sleeping...");
Sleepy::loseSomeTime(5000);
Serial.println("Awake!");
}
byte locked = lock.digiRead();
Serial.println(locked ? "LOCKED" : "UNLOCKED");
ledGreen.digiWrite(locked);
ledRed.digiWrite(!locked);
delay(100);
ledGreen.digiWrite(0);
ledRed.digiWrite(0);
if(rf12_easySend(&locked, sizeof locked)) {
Serial.println("Sending...");
if(!radioOn) rf12_sleep(-1); // turn the radio back on
radioOn = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment