LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
sound.h
Go to the documentation of this file.
1 /*
2  * sound.h
3  *
4  * Created: 25.08.2011 09:53:05
5  * Author: rolo
6  */
7 
8 
9 #ifndef SOUND_H_
10 #define SOUND_H_
11 
12 extern uint8_t sndToneCnt;
13 extern uint8_t sndSeqPlaying;
14 
15 extern uint8_t sndErrorSeq[];
16 extern uint8_t sndSuccessSeq[];
17 extern uint8_t sndBigBenSeq[];
18 extern uint8_t sndSig1[];
19 extern uint8_t sndSig2[];
20 
21 extern uint8_t *musicPtr;
22 
23 void SndToneOn(uint16_t tone);
24 void SndToneOff(void);
25 void PlayTone(uint16_t tone,uint8_t duration);
26 void PlayNote(uint8_t note,uint8_t duration);
27 void PlaySequence(uint8_t *seq);
28 
31 static inline void InitSound()
32 {
33  sndToneCnt=0;
34  sndSeqPlaying=0;
35  musicPtr=0; // no sequence currently playing
36 
37  TCCR3A=0b01000011; // Toggle OC3A on compare match
38  TCCR3B=0b00011000; // Fast PWM, clock off
39 }
40 
41 
44 static inline void SndTimerCallback()
45 {
46  if (sndToneCnt>0)
47  {
48  sndToneCnt--;
49  if (sndToneCnt==0)
50  {
51  if (musicPtr!=0) // Another note to play
52  {
53  if (*(musicPtr+1)==0) // duration 0?
54  {
55  musicPtr=0; // end of sequence
56  SndToneOff();
57  }
58  else
59  {
60  PlayNote(*musicPtr,*(musicPtr+1));
61  musicPtr+=2;
62  }
63  } else
64  {
65  SndToneOff();
66  }
67  }
68  }
69 }
70 
71 
72 
73 #endif /* SOUND_H_ */
void SndToneOff(void)
Stops playing a tone.
Definition: sound.c:55
uint8_t sndSig2[]
Sequence for alert output 2.
Definition: sound.c:148
void PlayTone(uint16_t tone, uint8_t duration)
Plays a single tone.
Definition: sound.c:67
uint8_t sndBigBenSeq[]
Big Ben Tone sequence.
Definition: sound.c:130
uint8_t sndSeqPlaying
Is !=0 while a sequence is playing.
Definition: sound.c:29
uint8_t sndErrorSeq[]
Tone sequence for error messages.
Definition: sound.c:122
static void SndTimerCallback()
Must be called by system timer (10ms)
Definition: sound.h:44
void SndToneOn(uint16_t tone)
Starts playing a tone.
Definition: sound.c:47
uint8_t * musicPtr
Is used in the timer callback to play sequences.
Definition: sound.c:30
uint8_t sndSuccessSeq[]
Tone sequence for success.
Definition: sound.c:126
uint8_t sndSig1[]
Sequence for alert output 1.
Definition: sound.c:141
void PlaySequence(uint8_t *seq)
Plays a sequence of notes.
Definition: sound.c:107
void PlayNote(uint8_t note, uint8_t duration)
Plays a single note.
Definition: sound.c:88
static void InitSound()
Initializes sound hardware and state.
Definition: sound.h:31
uint8_t sndToneCnt
Down-counter for tone duration. Can be tested to 0 to wait for end of tone.
Definition: sound.c:28