Class SoftTone
- java.lang.Object
-
- com.pi4j.wiringpi.SoftTone
-
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/)
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
- See Also:
- https://pi4j.com/, http://wiringpi.com/reference/software-tone-library/
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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);
-
-
-
Method Detail
-
softToneCreate
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.
- Parameters:
pin
- The GPIO pin to use as a PWM pin.- Returns:
- The return value is 0 for success. Anything else and you should check the global errno variable to see what went wrong.
- See Also:
- http://wiringpi.com/reference/software-tone-library/
-
softToneWrite
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.
- Parameters:
pin
- The GPIO pin to use.frequency
- The frequency value set on the GPIO pin. Set of value of '0' to stop the tone.- See Also:
- http://wiringpi.com/reference/software-tone-library/
-
softToneStop
public static void softToneStop(int pin)
void softToneStop (int pin);
This stops any tone frequency value on the given pin.
- Parameters:
pin
- The GPIO pin to use.- See Also:
- http://wiringpi.com/reference/software-tone-library/
-
-