IRReceiver

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderators: roger, 99jonathan, imaqine

IRReceiver

Postby NoTarget » Mon Jan 14, 2013 1:12 pm

Hi Guys, i am very new to leJOS. It's a nice language but i dosen't find any hint how i can user the IRReceiver from HiTechnic.
All i can find is code for the IRLink and the IRSeeker. Can someone help me?

greetings NoTarget
NoTarget
New User
 
Posts: 2
Joined: Mon Jan 14, 2013 1:09 pm

Re: IRReceiver

Postby gloomyandy » Mon Jan 14, 2013 1:51 pm

Hi,
there is no class to support this device at the moment in the standard leJOS release. The only sensors supported by leJOS are those which either members of the development team posses, or which have been contributed by leJOS users. You may be able to write your own (all of the sensor drivers are written in Java and the source code for them is provided with the leJOS install), or you may be able to find another user that has already written a class for it. It looks like the sensor is a relatively straight forward i2c device, so creating a new class should not that difficult.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3003
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: IRReceiver

Postby NoTarget » Tue Jan 15, 2013 6:41 am

Ok, here we go.. I write a class which returns the Value -100, 0 or 100.
How to use it:

Code: Select all
IRReceiver ir = new IRReceiver(SensorPort.S1);
value = ir.getChannelValue(2,1);


The first parameter in getChannelValue is the channel where the remote sends a signal and the second parameter is the stick - 1 is the left stick, 2 is the right one!.
I was not able to convert the "buf" (byte[]) varriable to a int so i solved the problem with the stick parameter.

Code: Select all
package lejos.nxt.addon;

import lejos.nxt.I2CPort;


public class IRReceiver extends IRSeeker {
   byte[] buf = new byte[2];
   
   public IRReceiver(I2CPort port) {
      super(port);
   }
   
   public int getChannelValue(int channel, int stick) {
      if (channel <= 0 || channel > 5) return -1;
      if (stick <= 0 || stick > 2) return -1;
      int ret = getData(0x42 + ((channel - 1) * 2), buf, 2);
      if(ret != 0) return -1;
      return (buf[stick - 1]);
   }
}



hope i can help someone!
NoTarget
New User
 
Posts: 2
Joined: Mon Jan 14, 2013 1:09 pm


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff