I have to sleep the system in the night and have to wake the system in day time. I am using LDR to get input. LDR input is connected to interrupt pin 0 of Arduino Uno.
Here is my code.
#include <avr/sleep.h>
int led =13;
int triggerPin = 2;
void wakeUpNow()
{
}
void setup()
{
pinMode(triggerPin, INPUT);
pinMode(led, OUTPUT);
attachInterrupt(0, sleepNow, LOW);
}
void loop()
{
digitalWrite(led, HIGH);;
delay(1000);
digitalWrite(led, LOW);
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(0,wakeUpNow, RISING);
sleep_mode();
sleep_disable();
detachInterrupt(0);
}
Cannot we attach two function in a interrupt?
Edited The following code works perfectly. I want to replace the conditional check with interrupt.
#include <avr/sleep.h>
int led =13;
int wakePin = 2;
void wakeUpNow()
{
delay(100);
}
void setup()
{
pinMode(wakePin, INPUT);
pinMode(led, OUTPUT);
//attachInterrupt(0, sleepNow, LOW);
}
void loop()
{
digitalWrite(led, HIGH);;
delay(1000);
digitalWrite(led, LOW);
if(digitalRead(wakePin)==LOW)
sleepNow();
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(0,wakeUpNow, RISING); function
sleep_mode();
sleep_disable();
detachInterrupt(0);
}
I want to replace `
if(digitalRead(wakePin)==LOW)
sleepNow()
with`
attachInterrupt(0, sleepNow, LOW);
Please let me know how I can do that.
Thank you.