when compiling, I got errors.
Seems the old version uses: SIG_INTERRUPT0 and the new version uses INT0_vect; I have tried them both, and they don't work.
I am doing a simple power-down interrupt using INT0, to wake it up. I know I can achieve it using attachInterrupt(), tested it on an atmega8 board; but attachInterrupt() is not supported for the avr that I am programming. I have done some research prior testing this <avr/interrupt.h>. still very confusing thing to get!!
#include <avr/sleep.h>
#include <avr/interrupt.h>
int ledOut[10]={0,1,4,5,6,7,8,13}; //map out 10 led pins
int ledCount=0;
int counter=1;
int scount=0;
void setup() {
for (int x=0; x<8;x++){
pinMode(ledOut[x], OUTPUT);}
}
void loop() {
digitalWrite(ledOut[ledCount], HIGH);
if(counter==1)digitalWrite(ledOut[ledCount-1], LOW);
if(counter==-1)digitalWrite(ledOut[ledCount+1], LOW);
if(ledCount==7){counter=-1;}
if(ledCount==0){counter=1;}
ledCount=ledCount+counter;
scount++;
delay(100);
if(scount>=100){
digitalWrite(ledOut[ledCount-1], LOW);
digitalWrite(ledOut[ledCount+1], LOW);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
ISR(INT0_vect) { // this is the problem
sleep_disable();
scount=0;
}
sleep_mode();
}
}
Here are error message
.ino: In function 'void loop()':
.ino:41:3: error: expected unqualified-id before string constant
.ino:41:18: error: a function-definition is not allowed here before '{' token
.ino:49:1: error: expected '}' at end of input
.ino:49:1: error: expected '}' at end of input
Don't stay behind, use the newest Arduino 1.6.7.
Tell us for which microcontroller you are compiling.
Write the source code with consistant text layout. Try the "Tools / Auto Format" in the menu.
Create an interrupt function in the same way as writing a function, outside the loop() as others already wrote.
Koepel:
Don't stay behind, use the newest Arduino 1.6.7.
Tell us for which microcontroller you are compiling.
Write the source code with consistant text layout. Try the "Tools / Auto Format" in the menu.
Create an interrupt function in the same way as writing a function, outside the loop() as others already wrote.
If it's not broken, it doesn't need to fixed. 1.6.3 is good enough for me. I am doing attinys, attiny13A to be exact, but seems to me that it doesn't really have an external interrupt thing. so the codes that I was writing can only be tested on an atmega8. got to figure out how to do it on an attiny kid.
Got it for the attiny13A. here is the code to flash a led for 3 second and power the mcu down, and with a push of a button, it powers on again, and flashes a led for 3 second again.
'toggle' is an integer, and you use a boolean operation on it. I think it is better to make that a bool.
Keep up with the newest Arduino IDE version. There are bug fixed and improvements for both the IDE and the libraries all the time.
The argument not to fix it when it is not broken is not for this situation. You might be asking questions about a bug that was solved a few versions ago.
I have used ATtiny13A, but not together with Arduino, although I used a lot defines and macros to make the source almost Arduino code.
'toggle' is an integer, and you use a boolean operation on it. I think it is better to make that a bool.
Keep up with the newest Arduino IDE version. There are bug fixed and improvements for both the IDE and the libraries all the time.
The argument not to fix it when it is not broken is not for this situation. You might be asking questions about a bug that was solved a few versions ago.
I have used ATtiny13A, but not together with Arduino, although I used a lot defines and macros to make the source almost Arduino code.
It's not like if it's a love letter. I don't think the compiler mind about the indentations. The newest version should have some tiny bugs too, it's not deadly, we can live with them, and also never have a bug from the IDE that costs any problem so far, since most bugs are from my own lacking of programming knowledge. At worst, you have a friend in the mcu business, and his name is called the WatchDog. Working ATtiny13A with Arduino is pita. smallest stretch already use up 16% of its memory. IS the arduino IDE very bad at memory management?