Hi The idea is of having an IRQ every 16 mSec using an old board Leonardo of arduino.
The question is why it not recognize the registers
``
#include <Arduino.h>
int16_t button_store;
void setup() {
//Let’s setup a interrupt that will check the key inputs on the analog input A0.
TCCR2A = 0; //Make sure that the TCCR2A register is set to zero
TCCR2B = 0; //Make sure that the TCCR2A register is set to zero
TIMSK2 |= (1 << OCIE2A); //Set the interupt enable bit OCIE2A in the TIMSK2 register
//Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20);
//The compare register is set to 249 => 16ms / (1s / (16.000.000MHz / 1024)) - 1 = 249
OCR2A = 249;
TCCR2A |= (1 << WGM21); //Set counter 2 to CTC (clear timer on compare) mode
}
void loop() {
// put your main code here, to run repeatedly:
}
ISR(TIMER2_COMPA_vect){
if(button_store == -1)button_store = analogRead(0);
if(button_store > 1000)button_store = -1;
}
platformio.ini
[env:leonardo]
platform = atmelavr
board = leonardo
framework = arduino
=========MKING IT RESULT
src\main.cpp: In function ‘void setup()’:
src\main.cpp:9:3: error: ‘TCCR2A’ was not declared in this scope
TCCR2A = 0; //Make sure that the TCCR2A register is set to zero
^~~~~~
src\main.cpp:9:3: note: suggested alternative: ‘TCCR0A’
TCCR2A = 0; //Make sure that the TCCR2A register is set to zero
^~~~~~
TCCR0A
src\main.cpp:10:3: error: ‘TCCR2B’ was not declared in this scope
TCCR2B = 0; //Make sure that the TCCR2A register is set to zero
^~~~~~
src\main.cpp:10:3: note: suggested alternative: ‘TCCR0B’
TCCR2B = 0; //Make sure that the TCCR2A register is set to zero
^~~~~~
TCCR0B
src\main.cpp:11:3: error: ‘TIMSK2’ was not declared in this scope
TIMSK2 |= (1 << OCIE2A); //Set the interupt enable bit OCIE2A in the TIMSK2 register
^~~~~~
src\main.cpp:11:3: note: suggested alternative: ‘TIMSK0’
TIMSK2 |= (1 << OCIE2A); //Set the interupt enable bit OCIE2A in the TIMSK2 register
^~~~~~
TIMSK0
src\main.cpp:11:19: error: ‘OCIE2A’ was not declared in this scope
TIMSK2 |= (1 << OCIE2A); //Set the interupt enable bit OCIE2A in the TIMSK2 register
^~~~~~
src\main.cpp:11:19: note: suggested alternative: ‘OCIE0A’
TIMSK2 |= (1 << OCIE2A); //Set the interupt enable bit OCIE2A in the TIMSK2 register
^~~~~~
OCIE0A
src\main.cpp:12:19: error: ‘CS22’ was not declared in this scope
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
src\main.cpp:12:19: note: suggested alternative: ‘CS12’
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
CS12
src\main.cpp:12:29: error: ‘CS21’ was not declared in this scope
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
src\main.cpp:12:29: note: suggested alternative: ‘CS01’
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
CS01
src\main.cpp:12:39: error: ‘CS20’ was not declared in this scope
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
src\main.cpp:12:39: note: suggested alternative: ‘CS00’
TCCR2B |= (1 << CS22|1 << CS21|1 << CS20); //Set the CS20, CS21 and CS22 bit in the TCCRB register to set the prescaler to 1024
^~~~
CS00
src\main.cpp:13:3: error: ‘OCR2A’ was not declared in this scope
OCR2A = 249; //The compare register is set to 249 => 16ms / (1s / (16.000.000MHz / 1024)) - 1 = 249
^~~~~
src\main.cpp:13:3: note: suggested alternative: ‘OCR3A’
OCR2A = 249; //The compare register is set to 249 => 16ms / (1s / (16.000.000MHz / 1024)) - 1 = 249
^~~~~
OCR3A
src\main.cpp:14:19: error: ‘WGM21’ was not declared in this scope
TCCR2A |= (1 << WGM21); //Set counter 2 to CTC (clear timer on compare) mode
^~~~~
src\main.cpp:14:19: note: suggested alternative: ‘WGM41’
TCCR2A |= (1 << WGM21); //Set counter 2 to CTC (clear timer on compare) mode
^~~~~
WGM41
In file included from C:\Users\gsrad.platformio\packages\framework-arduino-avr\cores\arduino/Arduino.h:30:0,
from src\main.cpp:1:
src\main.cpp: In function ‘void TIMER2_COMPA_vect()’:
src\main.cpp:22:5: warning: ‘TIMER2_COMPA_vect’ appears to be a misspelled ‘signal’ handler, missing ‘__vector’ prefix [-Wmisspelled-isr]
ISR(TIMER2_COMPA_vect){
^
Adding these no difference
#include <avr/io.h>
#include <avr/interrupt.h>