To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 274
273  |  275
Subject: 
Sensor listener
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Fri, 19 Sep 2003 10:17:19 GMT
Viewed: 
5136 times
  
Hello!

I'm using a Sensor listener to read a sensor in a behavior class.

This is the code:

public class Angestossen implements Behavior, SensorListener
  {
    public void stateChanged(Sensor touchsensor, int oldValue, int
newValue)
    {
      if (touchsensor.readBooleanValue() ==true)
        { angestossen=true;
          Sound.systemSound(false, 2);
        }
    }

It seems to work fine.

If I include code to play a sound if the touchsensor releases, then the
second sound is played steadily, if the sensor is not pressed and the
value was not changed:

  if (touchsensor.readBooleanValue() ==true)
        { angestossen=true;
          Sound.systemSound(false, 2);
        }
  else
     Sound.systemSound(false, 0);


This is unexpected. What I expected was, that the second sound is played
only once, when the sensor is released, because the stateChanged()
should be only executed, if the sensor state really changed.  Is there
anything wrong in my code or does the sensor listener not work correct?

Regards
Michael



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR