onebutton library combined with sleep mode on attiny85


i'm using power saving functions , onebutton library together

my issue can wake attiny85 sleep double click not button hold.

can shade light on me?

edit: changed click times , works, can still explain it? has stumped me while.

code: [select]


#include <onebutton.h>
#include <avr/sleep.h>    // sleep modes
#include <avr/power.h>    // power management
#include <avr/wdt.h>      // watchdog timer

//int emitter = 0;
int starterdelay = 1450; //1392 time between starter signal being send , actual data signal
int interpulsedelay = 20; //delay between data pulses milliseconds
unsigned long int sleeptimer = 0;
int scoreincrease = 0;

boolean clickfound = false;
int deepsleep = 0;

onebutton button(2, false);

isr (pcint0_vect)
{
// interesting here
}

void setup()
{
 
 resetwatchdog ();
//portb = 0;
 
 pinmode(0, output);
 button.attachdoubleclick(doubleclick);
 button.attachpress(held);

 button.setclickticks(300);
 button.setpressticks(800);

  ddrb =  0b00000011; // set pb1 (= ocr1a) output
  setfrequency(38000);
 
 pcmsk  |= bit (pcint2);  // want pin d4 / pin 3
 gifr   |= bit (pcif);    // clear outstanding interrupts
 gimsk  |= bit (pcie);    // enable pin change interrupts
}

void loop()
{
 button.tick();
 
 
    //sleepmodea();
 sleeptimer++;
 
 if(sleeptimer > 24000)
 {
  sleeptimer = 0;
  //deepsleep++;
  //clickfound = false;
  sleepmodea();
 }

}

//**************************************************************************************************************

void doubleclick()
{
 int bubs = random(0,7);
  if(bubs > 3)
  {
     for (int x = 0; x < 3; x++)
     {
     three();
     delay(interpulsedelay);
     }
  }
  else
  {
     for (int x = 0; x < 3; x++)
     {
     four();
     delay(interpulsedelay);
     }
  }
 
 //checker light
  for(int =0; < 6;)
 {
   digitalwrite(0, high);
 delay(50);
 digitalwrite(0,low);
 delay(50);
 a++;
 }
 
 clickfound = true;
 sleeptimer = 0;
}

void held()
{
 int bubs = random(0,7);
  if(bubs > 3)
  {
     for (int x = 0; x < 3; x++)
     {
     nine();
     delay(interpulsedelay);
     }
  }
  else
  {
          (int x = 0; x < 3; x++)
     {
     ten();
     delay(interpulsedelay);
     }
  }
 
 //checker light
 for(int =0; < 3;)
 {
 digitalwrite(0, high);
 delay(100);
 digitalwrite(0,low);
 delay(100);
 a++;
 }
 
 clickfound = true;
 sleeptimer = 0;
}


isr (wdt_vect)
{
  wdt_disable();  // disable watchdog
}  // end of wdt_vect

void resetwatchdog ()
 {
 // clear various "reset" flags
 mcusr = 0;    
 // allow changes, disable reset, clear existing interrupt
 wdtcr = bit (wdce) | bit (wde) | bit (wdif);
 // set interrupt mode , interval (wde must changed 1 0 here)
 wdtcr = bit (wdie) | bit (wdp3) | bit (wdp0);    // set wdie, , 8 seconds delay
 // pat dog
 wdt_reset();  
 }  // end of resetwatchdog
 
void sleepmodea ()
 {
   oneogma();
 set_sleep_mode (sleep_mode_pwr_down);
 adcsra = 0;            // turn off adc
 power_all_disable ();  // power off adc, timer 0 , 1, serial interface
 nointerrupts ();       // timed sequence coming up
 resetwatchdog ();      // watchdog ready
 sleep_enable ();       // ready sleep
 interrupts ();         // interrupts required now
 sleep_cpu ();          // sleep                
 sleep_disable ();      // precaution
 power_all_enable ();   // power on
 }  // end of sleepmodea



thanks, gmcg

hi,gmcglinn
you solved problem? if yes, how?


Arduino Forum > Using Arduino > Programming Questions > onebutton library combined with sleep mode on attiny85


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support