SunSPOT API V3.0


com.sun.spot.sensorboard.peripheral
Class ToneGenerator

java.lang.Object
  extended by com.sun.spot.sensorboard.peripheral.ToneGenerator
All Implemented Interfaces:
IToneGenerator

public class ToneGenerator
extends Object
implements IToneGenerator

Allows attaching a simple speaker device to an output pin to generate various simple frequencies. Note: the tone will stop during deep sleep and resume when deep sleep is over. The core of the work is done by the microcontroller on the sensorboard.

Author:
arshan

Field Summary
static int PERIOD_CONSTANT
          Constant used to calculate the period of the tone given the desired frequency.
 
Constructor Summary
ToneGenerator(IOutputPin pin)
          Creates a new instance of ToneGenerator.
 
Method Summary
 void beep()
          initiate a tone that will be asynchrounously stopped
 void endTone()
          Ask the ToneGenerator to stop generating the tone.
 double getFrequency()
          Returns the current value of the ToneGenerators frequency in Hertz
 void setDuration(int ms)
          Sets the duration of the asynchronous beep.
 void setFrequency(double hz)
          Sets the frequency that this tone generator is operating at.
 void setPeriod(int p)
          Set the period of the tone generated.
 void startTone()
          Ask the tonegenerator to begin generating the tone.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERIOD_CONSTANT

public static final int PERIOD_CONSTANT
Constant used to calculate the period of the tone given the desired frequency. PERIOD_CONSTANT / Frequency (hz) = period

See Also:
Constant Field Values
Constructor Detail

ToneGenerator

public ToneGenerator(IOutputPin pin)
Creates a new instance of ToneGenerator.

Parameters:
pin - where is the output device attached to the spot.
Method Detail

setFrequency

public void setFrequency(double hz)
Sets the frequency that this tone generator is operating at.

Specified by:
setFrequency in interface IToneGenerator
Parameters:
hz - the frequency to set the tone to

getFrequency

public double getFrequency()
Returns the current value of the ToneGenerators frequency in Hertz

Specified by:
getFrequency in interface IToneGenerator
Returns:
frequency value in hertz

setPeriod

public void setPeriod(int p)
Set the period of the tone generated. This value is an internal value that can be created by using the formula PERIOD_CONSTANT/Frequency(hz).

Parameters:
p - value to set the period to

setDuration

public void setDuration(int ms)
Sets the duration of the asynchronous beep.

Specified by:
setDuration in interface IToneGenerator
Parameters:
ms - duration in milliseconds

startTone

public void startTone()
Ask the tonegenerator to begin generating the tone.

Specified by:
startTone in interface IToneGenerator

endTone

public void endTone()
Ask the ToneGenerator to stop generating the tone.

Specified by:
endTone in interface IToneGenerator

beep

public void beep()
initiate a tone that will be asynchrounously stopped

Specified by:
beep in interface IToneGenerator

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.