forked from microbuilder/LPC810_CodeBase
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtone.c
More file actions
43 lines (35 loc) · 818 Bytes
/
tone.c
File metadata and controls
43 lines (35 loc) · 818 Bytes
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
/**************************************************************************/
/*!
@file tone.c
@author ChrisMicro
@brief sound generator
@section LICENSE see below for my code contribution
*/
/**************************************************************************/
#include "arduino.h"
#include "tone.h"
#include "mrt.h"
uint8_t TonePin;
void arduinoSound(uint16_t frequency, uint16_t duration_ms)
{
uint16_t n;
uint32_t delay_us;
delay_us=1000000UL/frequency/2;
//cli();
for(n=0;n<(duration_ms*1000/delay_us);n++)
{
digitalToggle(TonePin);
delayMicroseconds(delay_us);
}
//sei();
}
void tone(uint8_t pin, uint32_t frequency, uint16_t duration_ms)
{
pinMode(pin, OUTPUT);
TonePin=pin;
arduinoSound(frequency, duration_ms);
}
void noTone(uint8_t pin)
{
// tbd
}