SunSPOT API V6.0


com.sun.spot.sensorboard.peripheral
Class ToneGenerator

java.lang.Object
  extended by com.sun.spot.resources.Resource
      extended by com.sun.spot.sensorboard.peripheral.ToneGenerator
All Implemented Interfaces:
IResource, IToneGenerator, ITransducer

public class ToneGenerator
extends Resource
implements IToneGenerator, 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. Note: for the eDemoboard the waveform generated for frequencies above 2000 Hz will have increasing jitter. The maximum frequency that can be set is 20,000Hz.

Author:
arshan, ron (modified for Yellow, July 2010)

Field Summary
static int MAX_FREQUENCY
           
static int PERIOD_CONSTANT
          Deprecated.  
 
Constructor Summary
ToneGenerator(IOutputPin pin)
          Creates a new instance of ToneGenerator.
 
Method Summary
 void beep()
          Deprecated. Please use startTone(double hz, int dur) instead
 SensorEvent createSensorEvent()
          Create a SensorEvent of the appropriate type for this sensor.
 void endTone()
          Deprecated. Please use stopTone() instead
 String getDescription()
          This method returns a readable description of the sensor.
 double getFrequency()
          Deprecated.  
 double getMaxSamplingRate()
          Return the maximum sampling rate per second for this sensor.
 void saveEventState(SensorEvent evt)
          Save the current sensor state in the specified event.
 void setDuration(int ms)
          Deprecated. Please use startTone(double hz, int dur) instead
 void setFrequency(double hz)
          Deprecated. please specify the desired frequency in the call to startTone()
 void setPeriod(int p)
          Deprecated. please specify the desired frequency in the call to startTone()
 void startTone()
          Deprecated. Please use startTone(double hz) instead
 void startTone(double hz)
          start a tone at the specified frequency
 void startTone(double hz, int dur)
          start a tone at the specified frequency for the specified duration
 void stopTone()
          stop current tone
 
Methods inherited from class com.sun.spot.resources.Resource
addTag, getTags, getTagValue, hasTag, removeTag
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.spot.resources.IResource
addTag, getTags, getTagValue, hasTag, removeTag
 

Field Detail

PERIOD_CONSTANT

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

See Also:
Constant Field Values

MAX_FREQUENCY

public static final int MAX_FREQUENCY
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

startTone

public void startTone(double hz)
start a tone at the specified frequency

Specified by:
startTone in interface IToneGenerator
Parameters:
hz - value of frequency in Hertz

startTone

public void startTone(double hz,
                      int dur)
start a tone at the specified frequency for the specified duration

Specified by:
startTone in interface IToneGenerator
Parameters:
hz - value of frequency in Hertz
dur - the time of the duration in milliseconds

stopTone

public void stopTone()
stop current tone

Specified by:
stopTone in interface IToneGenerator

setFrequency

public void setFrequency(double hz)
Deprecated. please specify the desired frequency in the call to startTone()

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

setPeriod

public void setPeriod(int p)
Deprecated. please specify the desired frequency in the call to startTone()

Sets the period that this tone generator is operating at. This value is an internal value that can be created by using the formula period = PERIOD_CONSTANT/Frequency(hz).

Parameters:
p - the period to set the tone to (in microseconds)

getFrequency

public double getFrequency()
Deprecated. 

Returns the current value of the ToneGenerators frequency in Hertz

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

setDuration

public void setDuration(int ms)
Deprecated. Please use startTone(double hz, int dur) instead

Sets the duration of the asynchronous play.

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

startTone

public void startTone()
Deprecated. Please use startTone(double hz) instead

Ask the ToneGenerator to begin generating the tone.

Specified by:
startTone in interface IToneGenerator

endTone

public void endTone()
Deprecated. Please use stopTone() instead

Ask the ToneGenerator to stop generating the tone.

Specified by:
endTone in interface IToneGenerator

beep

public void beep()
Deprecated. Please use startTone(double hz, int dur) instead

initiate a tone that will be asynchronously stopped

Specified by:
beep in interface IToneGenerator

getDescription

public String getDescription()
Description copied from interface: ITransducer
This method returns a readable description of the sensor. The description should tell the essentials of the sensor, including at least the sensor type (accelerometer, microphone, thermometer). The returned string MUST not be null or an empty string.

Specified by:
getDescription in interface ITransducer
Returns:
the description of the sensor

getMaxSamplingRate

public double getMaxSamplingRate()
Description copied from interface: ITransducer
Return the maximum sampling rate per second for this sensor.

Specified by:
getMaxSamplingRate in interface ITransducer
Returns:
the maximum sampling rate per second for this sensor or 0 if not applicable.

createSensorEvent

public SensorEvent createSensorEvent()
Description copied from interface: ITransducer
Create a SensorEvent of the appropriate type for this sensor.

Specified by:
createSensorEvent in interface ITransducer
Returns:
a SensorEvent of the appropriate type for this sensor.

saveEventState

public void saveEventState(SensorEvent evt)
Description copied from interface: ITransducer
Save the current sensor state in the specified event.

Specified by:
saveEventState in interface ITransducer
Parameters:
evt - the event to store the sensor state in

SunSPOT API V6.0


Copyright © 2006-2010 Oracle. All Rights Reserved.