I copied and pasted this code from Adafruits and I received a few error codes. But I have no idea how to fix them!
The ones I get are
error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
This is the lines above it (and including the error line)
void interruptSetup(){
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}
// THIS IS THE TIMER 2 INTERRUPT SERVICE ROUTINE.
// Timer 2 makes sure that we take a reading every 2 miliseconds
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
Help please and sorry for taking your time
Arduino error codes on adafruit codes
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88042
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino error codes on adafruit codes
Please post the complete error message and a link to the code you are trying to compile.
Also please tell us what processor you are compiling this for.
Also please tell us what processor you are compiling this for.
- ecolights
- Posts: 6
- Joined: Wed Sep 12, 2018 4:42 pm
Re: Arduino error codes on adafruit codes
Hello thank you for your help.
Here is the information you requested
Code error message:
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Adafruit Feather M0"
Frank_Vice:45:5: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
^
C:\Users\hp\Documents\Arduino\Frank_Vice\Frank_Vice.ino: In function 'void interruptSetup()':
Frank_Vice:36:3: error: 'TCCR2A' was not declared in this scope
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
^
Frank_Vice:37:3: error: 'TCCR2B' was not declared in this scope
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
^
Frank_Vice:38:3: error: 'OCR2A' was not declared in this scope
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
^
Frank_Vice:39:3: error: 'TIMSK2' was not declared in this scope
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
^
Frank_Vice:40:7: error: 'sei' was not declared in this scope
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
^
C:\Users\hp\Documents\Arduino\Frank_Vice\Frank_Vice.ino: At global scope:
Frank_Vice:45:4: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here is the code I am trying to use: https://learn.adafruit.com/pulse-sensor ... s/the-code
I am using Arduino IDE for my feather MO basic
Here is the information you requested
Code error message:
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Adafruit Feather M0"
Frank_Vice:45:5: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
^
C:\Users\hp\Documents\Arduino\Frank_Vice\Frank_Vice.ino: In function 'void interruptSetup()':
Frank_Vice:36:3: error: 'TCCR2A' was not declared in this scope
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE
^
Frank_Vice:37:3: error: 'TCCR2B' was not declared in this scope
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
^
Frank_Vice:38:3: error: 'OCR2A' was not declared in this scope
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE
^
Frank_Vice:39:3: error: 'TIMSK2' was not declared in this scope
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A
^
Frank_Vice:40:7: error: 'sei' was not declared in this scope
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
^
C:\Users\hp\Documents\Arduino\Frank_Vice\Frank_Vice.ino: At global scope:
Frank_Vice:45:4: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here is the code I am trying to use: https://learn.adafruit.com/pulse-sensor ... s/the-code
I am using Arduino IDE for my feather MO basic
- adafruit_support_bill
- Posts: 88042
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino error codes on adafruit codes
That code was written for an Arduino UNO - or other Atmega 328 based processor. The ISR, TCCRxx, OCRxx and TIMSKxx identifiers all refer to Atmega 328-specific timer and interrupt functions. These do not exist on M0-based processors.Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Adafruit Feather M0"
To run this code you will need to use an Atmega 328 - based processor such as the ones specified in the guide: https://learn.adafruit.com/pulse-sensor ... he-circuit
Please be positive and constructive with your questions and comments.