Advertisement
w0lfiesmith

Piezo buzzer test

Aug 15th, 2013
12,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | None | 0 0
  1. #define ALARM 3
  2.  
  3. float sinVal;
  4. int toneVal;
  5. void setup() {
  6.   pinMode(ALARM, OUTPUT);
  7. }
  8.  
  9. void loop() {
  10.   for (int x=0; x<180; x++) {
  11.     // convert degrees to radians then obtain sin value
  12.     sinVal = (sin(x*(3.1412/180)));
  13.     // generate a frequency from the sin value
  14.     toneVal = 2000+(int(sinVal*1000));
  15.     tone(ALARM, toneVal);
  16.   }
  17.        
  18. delay(100); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement