Yes, that is what Im trying to do, keep it awake. So I could either add it in the sleep() function after it wakes up:
void sleep(int ncycles){
nbr_sleeps ++;
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
power_adc_disable();
sleep_mode();
// CPU is now asleep and program execution completely halts!
// Once awake, execution will resume at this point if the
// watchdog is configured for resume rather than restart
delay(1000);
// When awake, disable sleep mode
sleep_disable();
power_all_enable();
}
or in the loop before it sleeps:
void loop(){
Serial.println("will sleep...");
delay(1000);
// sleep for 8 seconds
sleep(1);
digitalWrite(pulsePin, HIGH);
delayMicroseconds(1000); // Approximately 10% duty cycle @ 1KHz
digitalWrite(pulsePin, LOW);
delayMicroseconds(1000 - 100);
Serial.println("pulsed led...");
if (nbr_sleeps==99) {
Serial.println("running motor...");
runMotor();
nbr_sleeps=0;
}
}