Skip to content

Commit c87a2ab

Browse files
authored
Add files via upload
1 parent cd75ab2 commit c87a2ab

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <FreqPeriodCounter.h>
2+
//#include <Albert.h>
3+
#include <Streaming.h>
4+
#include <TimerOne.h>
5+
6+
/* Note: connect d3 to d9 */
7+
8+
const byte counterPin = 3; // connect d3 to d9
9+
const byte counterInterrupt = 1; // = d3
10+
const byte PWMpin = 9; // PWM only d9 or d10
11+
//const byte buzzerPin = 8;
12+
//const int PiezoBuzzerFreq = 2400;
13+
14+
FreqPeriodCounter counter(counterPin, micros);
15+
16+
void setup(void)
17+
{ Serial.begin(9600);
18+
//tone(buzzerPin, PiezoBuzzerFreq, 20);
19+
pinMode(PWMpin, OUTPUT);
20+
Timer1.initialize();
21+
testAll();
22+
Timer1.pwm(PWMpin, 300, 20000); // duty cycle [10 bit], period [us] <8388480
23+
attachInterrupt(counterInterrupt, counterISR, CHANGE);
24+
}
25+
26+
void loop(void)
27+
{ if(!counter.ready()) Serial << "\nwaiting";
28+
else Serial << endl << counter.level, counter.period, counter.pulseWidth, counter.pulseWidthLow;
29+
}
30+
31+
void counterISR()
32+
{ counter.poll();
33+
}
34+

0 commit comments

Comments
 (0)