public class SoftTone extends Object
WiringPi includes a software-driven sound handler capable of outputting a simple tone/square wave signal on any of the Raspberry Pi’s GPIO pins.
There are some limitations… To maintain a low CPU usage, the minimum pulse width is 100μS. That gives a maximum frequency of 1/0.0002 = 5000Hz.
Also note that while the routines run themselves at a higher and real-time priority, Linux can still affect the accuracy of the generated tone.
However, within these limitations, simple tones on a high impedance speaker or piezo sounder is possible.
NOTES: - Each pin activated in softTone mode uses approximately 0.5% of the CPU. - You need to keep your program running to maintain the sound output!
This library depends on the wiringPi native system library. (developed by Gordon Henderson @ http://wiringpi.com/)
Modifier and Type | Method and Description |
---|---|
static int |
softToneCreate(int pin)
int softToneCreate (int pin)
|
static void |
softToneStop(int pin)
void softToneStop (int pin);
|
static void |
softToneWrite(int pin,
int frequency)
void softToneWrite (int pin, int frequency);
|
public static int softToneCreate(int pin)
int softToneCreate (int pin)
This creates a software controlled tone pin. You can use any GPIO pin and the pin numbering will be that of the wiringPiSetup() function you used.
pin
- The GPIO pin to use as a PWM pin.
public static void softToneWrite(int pin, int frequency)
void softToneWrite (int pin, int frequency);
This updates the tone frequency value on the given pin. The tone will be played until you set the frequency to 0.
pin
- The GPIO pin to use.frequency
- The frequency value set on the GPIO pin. Set of value of '0' to stop the tone.public static void softToneStop(int pin)
void softToneStop (int pin);
This stops any tone frequency value on the given pin.
pin
- The GPIO pin to use.Copyright © 2012–2021 Pi4J. All rights reserved.