add existing fritzing documentation for window1, window2 and fridge

This commit is contained in:
Nicu Hodos 2020-01-01 15:01:50 +01:00
parent 24f24458b4
commit 4ea2f501de
9 changed files with 88 additions and 27 deletions

8
window1/README.md Normal file
View File

@ -0,0 +1,8 @@
# Window1
Sensor for mezzanine window
## Schema
![](./wiki/schema.png)
## Breadboard
![](./wiki/breadboard.png)

BIN
window1/wiki/breadboard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

BIN
window1/wiki/schema.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
window1/wiki/window1.fzz Normal file

Binary file not shown.

View File

@ -1,16 +1,24 @@
#include <TinyPower.h>
#include <Tiny.h>
#include <RCSwitch.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
// Utility macros
#define adc_disable() (ADCSRA &= ~_BV(ADEN)) // disable ADC (before power-off)
#define adc_enable() (ADCSRA |= _BV(ADEN)) // re-enable ADC
#define enable_pin_interrupts() (GIMSK |= _BV(PCIE)) // Enable Pin Change Interrupts
// Pins
#define SWITCH 0
#define SENDER 2
#define CONTROLLER 4
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
RCSwitch mySwitch = RCSwitch();
char* WND_OPEN = "00000000000000000000000001000001";
char* WND_CLOSED = "00000000000000000000000001100001";
volatile int counter = 0;
volatile bool shouldSend = true;
bool currentState = false;
int counter = 0;
bool currentState;
void setup() {
@ -18,38 +26,75 @@ void setup() {
pinMode(CONTROLLER, OUTPUT);
digitalWrite(CONTROLLER, LOW);
sensor.setup();
mySwitch.enableTransmit(SENDER);
mySwitch.setProtocol(2);
updateState();
sendWindowState();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
enable_pin_interrupts();
enableWdt();
TinyPower::setup();
TinyPower::enableWdt(WDTO_8S);
}
void loop() {
if (shouldSend) {
shouldSend = false;
currentState = digitalRead(SWITCH);
sensor.sendState(currentState);
sleep();
}
void updateState() {
currentState = digitalRead(SWITCH);
}
void sendWindowState() {
byte state = digitalRead(SWITCH);
if (state == HIGH) {
mySwitch.send(WND_OPEN);
} else {
mySwitch.send(WND_CLOSED);
}
TinyPower::sleep();
}
void sleep() {
PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
adc_disable();
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
sleep_disable(); // Clear SE bit
adc_enable();
sei(); // Enable interrupts
}
ISR(PCINT0_vect) {
shouldSend = true;
wdt_reset();
counter = 0;
TinyPower::enableWdt(WDTO_8S);
sendWindowState();
}
ISR(WDT_vect) {
bool state = digitalRead(SWITCH);
if (state != currentState) {
sendWindowState();
updateState();
return;
}
counter++;
if (counter == 1) {
shouldSend = true;
return;
}
if (counter % 75 == 0) {
shouldSend = true;
}
if (!currentState && counter >= 225) {
TinyPower::disableWdt();
if (counter % 76 == 0) {
sendWindowState();
counter = 0;
}
}
//enable the wdt for 8sec interrupt
void enableWdt()
{
MCUSR = 0x00;
WDTCR |= _BV(WDCE) | _BV(WDE);
WDTCR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0); //8192ms
}

8
window2/README.md Normal file
View File

@ -0,0 +1,8 @@
# Window2
Sensor for kids room window
## Schema
![](./wiki/schema.png)
## Breadboard
![](./wiki/breadboard.png)

BIN
window2/wiki/breadboard.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

BIN
window2/wiki/schema.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
window2/wiki/window2.fzz Normal file

Binary file not shown.