ASURO Library  2.80
sound.c
gehe zur Dokumentation dieser Datei
1 /****************************************************************************/
30 /*****************************************************************************
31 * *
32 * This program is free software; you can redistribute it and/or modify *
33 * it under the terms of the GNU General Public License as published by *
34 * the Free Software Foundation; either version 2 of the License, or *
35 * any later version. *
36 * *
37 *****************************************************************************/
38 #include "asuro.h"
39 
40 
41 
42 /****************************************************************************/
65 void Sound (
66  uint16_t freq,
67  uint16_t duration_msec,
68  uint8_t amplitude)
69 {
70  uint16_t wait_tics;
71  uint32_t n,k,period_usec,dauer_usec;
72 
73  period_usec = 1000000L / freq;
74  dauer_usec = 1000 * (uint32_t) duration_msec;
75  k = dauer_usec / period_usec;
76 
77  //IR Interuptfreq=36KHz
78  //Wavefreq=18KHz
79 
80  wait_tics = 18000 / freq;
81 
82  MotorSpeed (amplitude, amplitude);
83 
84  for (n = 0; n < k; n++)
85  {
86  MotorDir (FWD, FWD);
87  Sleep (wait_tics);
88  MotorDir (RWD, RWD);
89  Sleep (wait_tics);
90  }
91  MotorSpeed (0, 0);
92 }
93 
94 #define BEEP sound (1000, 100, 255)