Comments (6)
Access to the pin change interrupts is something that should be added to the Arduino core: https://github.com/arduino/Arduino/issues/248. We'd then pick it up for the ATtiny.
from attiny.
What do you mean by "should be added to the Arduino core"? It's part of the Arduino API, isn't it? (At least, it's working for mine :-) )
from attiny.
Are you talking about pin interrupts or pin change interrupts?
from attiny.
Hey Schtrudel, what it is working? I cant attach interrupts on my tiny85 :/
from attiny.
Hi eried.
I love these discussions with 3 messages in 3 years... :-) Reminds me of this joke: http://jokesareawesome.com/joke/869
Anyway, I don't remember how I solved it then, but later, I switched to another approach: I don't use attachInterrupt at all and use a few lines with the "native" mechanism. In my case, it detects the change on any of 2 buttons, and I detect which one in the ISR. Quick and dirty, but works very well for my use. Most of it shamelessly copied and adapted from https://bigdanzblog.wordpress.com/2014/08/10/attiny85-wake-from-sleep-on-pin-state-change-code-example/ [Thanks Big Dan]
For reference, the relevant parts of the code. I hope it can help.
////////////////////////////////////////////////////////////////////////////////////////////
#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
const int button1 = 4;
const int button2 = 3;
//...
volatile byte button2Pressed = 0; // Don't forget to declare your global handled in ISR as volatile
ISR(PCINT0_vect) {
if (digitalRead(button2))
button2Pressed = 1;
}
void setup()
{
//...
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
//...
}
void loop(){
//...
sleep();
if (button2Pressed) {
run_fun2();
}
else{
run_fun1();
}
//...
}
void sleep() {
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(button1); // Use button1 as interrupt pin
PCMSK |= _BV(button2); // Use button2 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK &= ~_BV(button1);
PCMSK &= ~_BV(button2);
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on
sei(); // Enable interrupts
} // sleep
from attiny.
Hahaha! I was thinking to reply in 1 more year but I am going to forget to do that, so thanks for the code! Iยดll use it that way too, it was 3 am and I was very frustrated led debugging the tiny85
from attiny.
Related Issues (20)
- I2c / TWI on ATtiny84
- Not working with Arduino IDE 1.8.x HOT 6
- delay() is taking a lot of time when setting 8MHZ and 16MHZ internal HOT 1
- Wire.h fails HOT 4
- Attiny library using in my project
- ATtiny45 doesn't connect to Uno HOT 1
- Error Uploading to Arduino
- Error while burning bootloader HOT 3
- add attiny26 HOT 1
- Pin Defines for direct port. EG. PB1, PA3 HOT 6
- Server down
- Board in Arduino IDE doesn't show the hardware
- Naming and confusion with similar projects HOT 1
- Invalid device signature HOT 1
- I2C not working corretly on ATTiny85 clone
- disable external reset HOT 1
- Version 1.0.2 gives "Error resolving FQBN: board"
- installation guide not available HOT 1
- I am getting the following error when i am compiling the code by selecting the board as attiny85, and if i compile the same code by selecting board as arduino nano ,i am getting no error. please help
- avrdude.conf file missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from attiny.