Notes on a piezo buzzer: tone() and noTone(). More...
Functions | |
| tone (pin, frequency, duration=None) | |
| Plays a square wave (a note) on a pin, for example for a piezo buzzer. | |
| noTone (pin) | |
| Stops a tone() on a pin. | |
Notes on a piezo buzzer: tone() and noTone().
| tone | ( | pin, | |
| frequency, | |||
| duration = None ) |
Plays a square wave (a note) on a pin, for example for a piezo buzzer.
Returns straight away (well under 1 ms); the note plays on while your code runs. The note is a square wave, high half the time, on the pin's PWM output, so the PWM pin pairs apply; it also sets the frequency of the pin next to it on the slice (see pwm() in phyduino.py).
Only one note at a time has a stop time: a new tone(), on any pin, cancels the last one's duration, so play notes one after another, each followed by a delay().
| pin | Pin number (8 is D8) or name ("D8"). |
| frequency | Frequency in Hz, 8 Hz and up; 0 is silence. |
| duration | Milliseconds to play for; None plays until noTone(). |
| ValueError | Unknown pin, an analogue-only pin (A3-A5), or the pin shares its PWM output with one already in use. |
| noTone | ( | pin | ) |
Stops a tone() on a pin.
Sets the pin's duty to 0, so it stays low. It does nothing to a pin that has had no tone() or analogWrite() since the program started.
| pin | Pin number (8 is D8) or name ("D8"). |