zajebiscie wrote:Please could you tell me how long it will take the arduino to go to sleep when it is on idle mode, and how can we reset the time to our own time after FSR is not in use?
When you call SleepNow, it will only take a few microseconds for the arduino to go to sleep.
I don't understand what you mean about resetting the time. Is there a clock associated with this project?
Thanks for your help. There is no clock associated with the project, but all i wanted my arduino to go to sleep (idle) when not in use, and i want to use FSR sensor to interrupt by waking up the arduino while pressing the FSR sensor, and as soon as FSR sensor is release, it will go back to sleep(idle) and move a motor to clockwise. Below is the code i have been working on for the past two days, please could you take a look at it and see if i m missing anything. thanks
- Code: Select all
DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
digitalWrite(13,HIGH); // turn pin 13 LED on
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there is a list of sleep modes which explains which clocks and
* wake up sources are available in which sleep modus.
* In the avr/sleep.h file, the call names of these sleep modus are to be found:
* The 5 different modes are:
* SLEEP_MODE_IDLE -the least power savings
* SLEEP_MODE_PWR_DOWN -the most power savings
* the power reduction management <avr/power.h> is described in
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
// Choose our preferred sleep mode:
// Set sleep enable (SE) bit:
// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
// Upon waking up, sketch continues from this point.
digitalWrite(13,HIGH); // turn LED on to indicate awake