-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterrupcao_interna_main.cpp
More file actions
61 lines (45 loc) · 1.05 KB
/
interrupcao_interna_main.cpp
File metadata and controls
61 lines (45 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*************************************************************
author: <Yuri de Castro Costa>
description:
Exemple of implementation of the Timer_Interruption_Provider class.
In his exemple Timer2 is set to interrupt 8000 times per second, incrementing
a counter. The Loop checks if the counter is more than 8000, making a led
blink every 2 seconds (1 second off, 1 second on).
*************************************************************/
#include "interrupcao_interna_main.h"
#include "tip.h"
#include <arduino.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>
int flag = 0, cont = 0;
void setup() {
pinMode( 8, OUTPUT);
pinMode( 6, OUTPUT);
digitalWrite(6, 0);
Timer_Interruption_Provider *tip;
tip = new Timer_Interruption_Provider();
tip->set_timer(8000, 2);
}
void loop() {
if( cont >= 8000)
{
flag = !flag;
digitalWrite(8, flag);
cont = 0;
}
}
ISR(TIMER0_COMPA_vect)
{
cont++;
}
ISR(TIMER1_COMPA_vect)
{
flag = !flag;
digitalWrite(8, flag);
cont = 0;
}
ISR(TIMER2_COMPA_vect)
{
cont++;
}