Skip to content

Instantly share code, notes, and snippets.

@remisarrailh
Last active December 15, 2015 21:29
Show Gist options
  • Save remisarrailh/5326086 to your computer and use it in GitHub Desktop.
Save remisarrailh/5326086 to your computer and use it in GitHub Desktop.
PIR eco test
/*
* Test capteur PIR avec économie d'énergie
* La LED et l'attiny85 s'allume lorsque l'état du capteur PIR changent
* Par Sarrailh Rémi
* Licence gplv3
* http://www.tldrlegal.com/l/GPL3
* Demonstration of the pin change interrupt
* LED sur digital pin 0
* Capteur PIR Interrupt sur digital pin 2
* Source: Alex d'Inside Gadgets (http://www.insidegadgets.com)
*/
#include <avr/sleep.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
int pinLed = 0;
void setup(){
pinMode(pinLed,OUTPUT); LED en Output
sbi(GIMSK,INT0); // Active l'interruption sur le capteur PIR
}
void loop(){
digitalWrite(pinLed,HIGH); // Allume la LED
delay(1000);
digitalWrite(pinLed,LOW);
system_sleep(); //Mode Sommeil pour l'attiny85
}
// Source: http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/
void system_sleep() {
cbi(ADCSRA,ADEN); // Déactive le convertisseur Analog to Digital
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Mode Sommeil le plus haut
sleep_mode(); // Activation du sommeil
sbi(ADCSRA,ADEN); // Réactivation du Analog to Digital converter
}
ISR(PCINT0_vect) { //Fonction activée lors du réveil, il n'y a rien à faire ici, tout est dans la boucle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment