Skip to content

Commit 2f4d76b

Browse files
authored
Add files via upload
1 parent 87d64e2 commit 2f4d76b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <Arduino.h>
2+
#include "Avdweb_SAMDtimer.h"
3+
4+
const byte LED1 = 3;
5+
const byte LED2 = 0;
6+
const byte LED3 = 2;
7+
const byte LED4 = 5; // timer3 16bit has 2 pins: 5 12
8+
9+
void ISR_timer3_LED1(struct tc_module *const module_inst)
10+
{ static bool b;
11+
pinMode(LED1, OUTPUT);
12+
digitalWrite(LED1, b=!b);
13+
}
14+
15+
void ISR_timer4_LED2(struct tc_module *const module_inst)
16+
{ static bool b;
17+
pinMode(LED2, OUTPUT);
18+
digitalWrite(LED2, b=!b);
19+
}
20+
21+
void ISR_timer4_LED3(struct tc_module *const module_inst)
22+
{ static bool b;
23+
pinMode(LED3, OUTPUT);
24+
digitalWrite(LED3, b=!b);
25+
}
26+
27+
// ------------- Timer3 with output, select 1 of 3 -------------
28+
SAMDtimer timer3_1Hz = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, LED4, 1e6, 9e5); // LED4 1Hz, pulse width 0.9s (this is the constructor)
29+
// SAMDtimer timer3_1Hz = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, LED4, 1e6, 9e5, 0); // the same but timer is disabled *1)
30+
// SAMDtimer timer3_1Hz = SAMDtimer(3, TC_COUNTER_SIZE_16BIT, LED4, 1e6); // default 50% duty cycle
31+
32+
// ------------- Timer4 with ISR, without output, select 1 of 2 -------------
33+
SAMDtimer timer4_2Hz = SAMDtimer(4, ISR_timer4_LED2, 5e5); // ISR LED2 1Hz (0.5s on, 0.5s off)
34+
// SAMDtimer timer4_2Hz = SAMDtimer(4, ISR_timer4_LED2, 5e5, 0); // the same but ISR is disabled *2)
35+
36+
void setup() // test out the several functions:
37+
{ // ------------- timer3 -------------
38+
// timer3_1Hz.enableTimer(1); // enable timer *1), LED4 blinks again
39+
// timer3_1Hz.setPulseWidth(1e5); // change pulse width to 0.1s
40+
41+
// attach a new ISR to a timer with output, this can't be done in the constructor
42+
timer3_1Hz.attachInterrupt(ISR_timer3_LED1); // LED1 blinks
43+
// timer3_1Hz.attachInterrupt(ISR_timer3_LED1, 0); // the same but ISR is disabled, the timer-output is not disabled
44+
45+
// ------------- timer4 -------------
46+
// timer4_2Hz.enableInterrupt(0); // disable ISR_timer4_LED2, LED2 stops blinking
47+
// timer4_2Hz.enableInterrupt(1); // enable ISR_timer4_LED2, LED2 blinks again *2)
48+
// timer4_2Hz.attachInterrupt(ISR_timer4_LED3); // exchange ISR_timer4_LED2 -> ISR_timer4_LED3, LED3 blinks
49+
}
50+
51+
void loop()
52+
{
53+
}
54+

0 commit comments

Comments
 (0)