7 Replies Latest reply on Jan 19, 2015 12:18 PM by gadget.iom

    Arduino Sleep, pin interrupt

    izwan_12

      I am trying to explore the codes for Arduino to sleep. I am trying to write a simple program whereby the LED will blink once and go to sleep. a button will then be pressed to wake up the Arduino and it will loop.

       

      Results: The LED blink once and goes to sleep. But when it wakes up, the LED stays on. Why is this so?

       

      My codes are as follows:

       


      #include <avr/sleep.h>

       

      int led = 4;

       

      void setup() {
        sleep_enable();
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        pinMode(led, OUTPUT);
        pinMode(2,INPUT);
      }

       

      void loop() {
        digitalWrite(led, HIGH);
        delay(1000);
        digitalWrite(led, LOW);
        attachInterrupt(0, interruptFunction, HIGH);
        sleep_cpu();
        }

       

      void interruptFunction() {
        sleep_disable();
        }