[ Main Page ]

Arduino PWMでブザー

PWMを使用して簡易的にブザー音を出力できる。下記例は、目覚ましの音に近い。5Vだと圧電サウンダはかなり大音響なので、抵抗で適宜電圧を落とすと良い。

	void setup() {
	  pinMode(6, OUTPUT);
	  OCR0A = 128;
	}
	
	void loop() {
	  TCCR0A |= B10000000;  
	  delay(100);
	  TCCR0A ^= B10000000;
	  delay(100);
	
	  TCCR0A |= B10000000;  
	  delay(100);
	  TCCR0A ^= B10000000;
	  delay(100);
	
	  TCCR0A |= B10000000;  
	  delay(100);
	  TCCR0A ^= B10000000;
	  delay(100);
	
	  TCCR0A |= B10000000;  
	  delay(100);
	  TCCR0A ^= B10000000;
	  delay(600);
	}
      
Gratitude and treachery are merely the two extremities of the same procession.
You have seen all of it that is worth staying for when the band and the gaudy
officials have gone by.
		-- Mark Twain, "Pudd'nhead Wilson's Calendar"

  <rindolf>  This reminds me of a fun discussion I had with my co-worker.
  <rindolf>  He had a Firefox window open with an ActiveState page and I
             read "Perl, PHP, Python, Tcl, XSLT".
  <rindolf>  So he said: "Heresy! C is the only language."
  <rindolf>  So I thought for a moment and said "Intercal is the only
             language."
 <nanonyme>  lol
  <rindolf>  And then "Real men write in Intercal."
  <rindolf>  "COME FROM" anyone?

    -- The Only Programming Language
    -- #perl, Freenode


Powered by UNIX fortune(6)
[ Main Page ]