Moderators: adafruit_support_bill, adafruit
driverblock wrote:Is the code working for you, or is there a problem with it?
void loop(void)
{
// Stay awake for 0.1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();
}driverblock wrote:Your loop function is doing that.
- Code: Select all
void loop(void)
{
// Stay awake for 0.1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();
}
When you call sleepNow, it will sleep until you touch the FSR. After you touch the FSR, the sleepNow function will return. The loop function will wait 100 milliseconds, and call sleepNow() again. And then the arduino will go back to sleep whether you're holding the FSR or not.
driverblock wrote:Your loop function is doing that.
- Code: Select all
void loop(void)
{
// Stay awake for 0.1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();
}
When you call sleepNow, it will sleep until you touch the FSR. After you touch the FSR, the sleepNow function will return. The loop function will wait 100 milliseconds, and call sleepNow() again. And then the arduino will go back to sleep whether you're holding the FSR or not.
void loop(void)
{
delay(100); //execute loop 10 times/second
if (HIGH == digitalRead(2)) // if the FSR is not pressed
{
sleepNow(); // then go to sleep. Stays asleep until FSR is pressed.
}
}driverblock wrote:OK. Try this:
- Code: Select all
void loop(void)
{
delay(100); //execute loop 10 times/second
if (HIGH == digitalRead(2)) // if the FSR is not pressed
{
sleepNow(); // then go to sleep. Stays asleep until FSR is pressed.
}
}
void sleepNow(void) {
sleep_enable();
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
set_sleep_mode(SLEEP_MODE_IDLE);
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
digitalWrite(13,LOW); // turn LED off to indicate sleep
sleep_mode();
digitalWrite(13,HIGH); // turn LED on to indicate awake
}
void pinInterrupt(void) {
sleep_disable();
detachInterrupt(0);
}// use arduino pins 2, 3, 4, 5 for DAC
// pin 2 is DAC chip select
/** Data direction register for DAC chip select. */
#define MCP_DAC_CS_DDR PIN2_DDRREG
/** Port register for DAC chip select. */
#define MCP_DAC_CS_PORT PIN2_PORTREG
/** Port bit number for DAC chip select. */
#define MCP_DAC_CS_BIT PIN2_BITNUM
// use arduino pins 3, 4, 5, 6 for DAC
// pin 6 is DAC chip select
/** Data direction register for DAC chip select. */
#define MCP_DAC_CS_DDR PIN6_DDRREG
/** Port register for DAC chip select. */
#define MCP_DAC_CS_PORT PIN6_PORTREG
/** Port bit number for DAC chip select. */
#define MCP_DAC_CS_BIT PIN6_BITNUM
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Users browsing this forum: No registered users and 10 guests