SensorPortListener and TouchSensor

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

SensorPortListener and TouchSensor

Postby nbeck » Sun Jun 03, 2007 8:34 pm

Hi! I just started using leJOS and am still getting acquainted with it. So I tried to write a very simple program using the TouchSensor and a SensorPortListener. Now I am trying to implement the stateChanged method, but I don´t know what value (oldValue and/or newValue) I can expect from the TouchSensor. I expected it to be either 1 or 0, but it wasn´t. I couldn´t find any information about this either.

Code: Select all
public void stateChanged(SensorPort port, int oldValue, int newValue) {
     //TouchSensor pressed
     if(newValue == ???)
     {
           //do something
     }
}


PS: I printed the values to the LCD, but they were something like 1023 and 1843 or 1833. When I tried using these values in my program, it didn´t work though...

Can someone tell me what values I can work with or point me to the documentation about them?
nbeck
New User
 
Posts: 2
Joined: Sun Jun 03, 2007 8:20 pm

Postby lawrie » Mon Jun 04, 2007 6:04 am

The stateChanged method currently has the raw sensor values in old and new value. It is best to use an instance of the specific sensor class (such as TouchSensor) in the stateChanged method to determine the current value. For touch sensors the raw value is 1023 when it is not pressed. Any value less than 600 is interpreted as pressed. I don't know where your value of 1800+ came from - raw sensor values should be 0-1023.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm

Postby nbeck » Mon Jun 04, 2007 9:29 am

Ok, I´ll just use an instance of the TouchSensor.

Thanx for your quick reply :)
nbeck
New User
 
Posts: 2
Joined: Sun Jun 03, 2007 8:20 pm


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

more stuff