Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/sleep.h>
- const byte LED = 9;
- /*Riattiva ARDUINO*/
- void wake ()
- {
- // cancello lo sleep mode
- sleep_disable();
- //disabilito l agestione dell'interapt
- detachInterrupt (0);
- }
- /*Setup*/
- void setup ()
- {
- digitalWrite (2, HIGH); // enable pull-up
- }
- /*Loop*/
- void loop ()
- {
- /*al primo ciclo accendo il led*/
- pinMode (LED, OUTPUT);
- digitalWrite (LED, HIGH);
- delay (550);
- digitalWrite (LED, LOW);
- delay (50);
- pinMode (LED, INPUT);
- // disabilito ADC
- ADCSRA = 0;
- set_sleep_mode (SLEEP_MODE_PWR_DOWN);
- sleep_enable();
- // Do not interrupt before we go to sleep, or the
- // ISR will detach interrupts and we won't wake.
- noInterrupts ();
- // prendo l'eveno, interapt quando D2 diventa LOWW
- attachInterrupt (0, wake, LOW);
- // turn off brown-out enable in software
- // BODS must be set to one and BODSE must be set to zero within four clock cycles
- MCUCR = bit (BODS) | bit (BODSE);
- // The BODS bit is automatically cleared after three clock cycles
- MCUCR = bit (BODS);
- /*si vuole garantire che la cpu venga spenta solo
- la successiva istruzione dell'attivazione di arduino*/
- /*Fà PARTIRE DI NUOVO IL LOOP*/
- interrupts (); // one cycle
- sleep_cpu (); // one cycle
- } // end of loop
Advertisement
Add Comment
Please, Sign In to add comment