All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pi4j.wiringpi.SoftTone Maven / Gradle / Ivy

package com.pi4j.wiringpi;

/*
 * #%L
 * **********************************************************************
ORGANIZATION  :  Pi4J
PROJECT       :  Pi4J :: Java Library (Core)
FILENAME      :  SoftTone.java

This file is part of the Pi4J project. More information about
this project can be found here:  http://www.pi4j.com/
**********************************************************************
 * %%
 * Copyright (C) 2012 - 2018 Pi4J
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 *
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * .
 * #L%
 */


import com.pi4j.util.NativeLibraryLoader;

/**
 * 

* 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/) *
*

* * @see http://www.pi4j.com/ * @see http://wiringpi.com/reference/software-tone-library/ * @author Robert Savage (http://www.savagehomeautomation.com) */ public class SoftTone { // private constructor private SoftTone() { // forbid object construction } static { // Load the platform library NativeLibraryLoader.load("libpi4j.so"); } /** *

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. *

* * @see http://wiringpi.com/reference/software-tone-library/ * * @param pin The GPIO pin to use as a PWM pin. *

* @return The return value is 0 for success. Anything else and you should check the global * errno variable to see what went wrong. */ public static native int softToneCreate(int pin); /** *

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. *

* * @see http://wiringpi.com/reference/software-tone-library/ * * @param pin The GPIO pin to use. * @param frequency The frequency value set on the GPIO pin. Set of value of '0' to stop the tone. */ public static native void softToneWrite(int pin, int frequency); /** *

void softToneStop (int pin);

* *

* This stops any tone frequency value on the given pin. *

* * @see http://wiringpi.com/reference/software-tone-library/ * * @param pin The GPIO pin to use. */ public static native void softToneStop(int pin); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy