Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve library examples #53

Closed
SpenceKonde opened this issue Jun 25, 2019 · 9 comments
Closed

Improve library examples #53

SpenceKonde opened this issue Jun 25, 2019 · 9 comments
Labels
enhancement New feature or request

Comments

@SpenceKonde
Copy link
Owner

Remove ones that aren't good examples and/or which don't compile on parts with small memory.

If this leaves an absence of basic examples, create some.

@SpenceKonde SpenceKonde added the enhancement New feature or request label Jun 25, 2019
@SpenceKonde SpenceKonde added this to the Some Future Version milestone Jun 25, 2019
@per1234
Copy link
Contributor

per1234 commented Jun 25, 2019

List of library examples that wouldn't compile for the 4x6 chips due to exceeding the available memory: #36 (comment)

@saysphilippe
Copy link

saysphilippe commented Jan 21, 2020

Hi Spence, It would be so awesome if you would create some SLEEP examples to show us how to do ex. STANDBY and PDOWN and react on an interrupt. I'm looking at using DS3231 or DS1337 for wake up towards the Attiny 1604 and1614. I have tried reading the chapter 11, but I'm not able to make that into actual code. :( Thanks to your library I created a meme: https://twitter.com/SaysPhilippe/status/1219529468349427713?s=20

@freemovers
Copy link
Collaborator

This might help to understand the use of sleep and interrupt:

#include <avr/sleep.h>

#define PB4_INTERRUPT PORTB.INTFLAGS & PIN4_bm
#define PB4_CLEAR_INTERRUPT_FLAG PORTB.INTFLAGS &= PIN4_bm

ISR(PORTB_PORT_vect)
{
    if(PB4_INTERRUPT)                                           // PB4 changed state (pin#5 on ATtiny1616)
    {
        digitalWrite(2, CHANGE);                              // toggle the LED
        PB4_CLEAR_INTERRUPT_FLAG;
    }
}

void PORT_init(void)
{
  for (uint8_t pin = 0; pin < 8; pin++) {           // Disable the pull-up resistors to conserve energy
    (&PORTA.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; // Disable on PAx pin
#ifdef PORTB
    (&PORTB.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; // Disable on PBx pin
#endif
#ifdef PORTC
    (&PORTC.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; // Disable on PCx pin
#endif
  }
    
  PORTB.DIRCLR = PIN4_bm;
  PORTB.PIN4CTRL = PORT_PULLUPEN_bm;
  PORTB.PIN4CTRL |= PORT_ISC_BOTHEDGES_gc;
}

void setup()
{
  PORT_init();

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // Set sleep mode to power down mode
  sleep_enable();                               // Enable sleep mode
  sei();                                         // Enable Interrupts

  pinMode(2, OUTPUT);                  // Set pin#2 as output 
}
 
void loop() {
    sleep_cpu();                               // Nothing to do here
}

@SpenceKonde
Copy link
Owner Author

SpenceKonde commented Jan 21, 2020 via email

@saysphilippe
Copy link

Thank you for your example @freemovers! And Spence: We are waiting in suspense, hehe.

@SpenceKonde
Copy link
Owner Author

Note that as of last night, the RTC millis function is in the github version, if that's what you're waiting in suspense for.

@saysphilippe
Copy link

Whoho! Let's try it!

@SpenceKonde
Copy link
Owner Author

2.1.0 will introduce some way cool stuff relating to sleep, including megaTinySleep which will let you use a civilized timer (ie, not the RTC) for millis, and switch to the RTC while sleeping so millis time is restored when it wakes back up.

But that's not coming out for a while - I have another pressing matter to attend to between 2.0.0 and 2.1.0...

@SpenceKonde
Copy link
Owner Author

Please open issues if other library issues are discovered. Please direct inquiries about sleep and millis-during-sleep to #158. Closing this issue as there are no known issues relating to this subject at this time.

@SpenceKonde SpenceKonde removed this from the Some Future Version milestone Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants