SHARE
TWEET

Piezo buzzer test

w0lfiesmith Aug 15th, 2013 8,762 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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); }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top