passivate() method in Light doesn't work

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

Moderators: roger, imaqine, 99jonathan

darthc0da
New User
Posts: 1
Joined: Sat May 26, 2007 9:31 pm

passivate() method in Light doesn't work

Postby darthc0da » Tue Jun 12, 2007 7:24 pm

Code: Select all

import icommand.platform.nxt.Light;
import icommand.platform.nxt.Sensor;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;

public class DDWD extends Applet {
   private Light lightsensor;
   private LinkedList dataLightOff;
   private LinkedList dataLightOn;
   public void init() {
      resize(1000,500);
      System.out.println("resizing");
      final Graphics g = getGraphics();
      lightsensor = new Light(Sensor.S1);
      dataLightOff = new LinkedList();
      dataLightOn = new LinkedList();
      System.out.println("setting up queue's and sensors");
      for(int i = 0; i < 100; i ++){
         dataLightOff.add(new Integer(0));
         dataLightOn.add(new Integer(0));
      }
      lightsensor.passivate();
      int delay = 1000; // delay for 5 sec.
      int period = 100; // repeat every sec.
      Timer timer = new Timer();
      System.out.println("starting timertask");
      timer.scheduleAtFixedRate(new TimerTask() {
         public void run() {
            System.out.println(dataLightOff.getLast() + "," + dataLightOn.getLast());
            g.setColor(Color.WHITE);
            g.fillRect(0,0,1000,500);
            for(int i = 0; i < 99; i ++){
               g.setColor(Color.RED);
               g.drawLine((i+1)*10,500-(((Integer)dataLightOff.get(i+1)).intValue())*5,i*10
                     ,500-(((Integer)dataLightOff.get(i)).intValue())*5);
               g.setColor(Color.GREEN);
               g.drawLine((i+1)*10,500-(((Integer)dataLightOn.get(i+1)).intValue())*5,i*10
                     ,500-(((Integer)dataLightOn.get(i)).intValue())*5);
            }
            lightsensor.passivate();
            try {
               Thread.sleep(25);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
            dataLightOff.add(new Integer(lightsensor.getLightPercent()));
            dataLightOff.removeFirst();
            lightsensor.activate();
            try {
               Thread.sleep(50);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
            dataLightOn.add(new Integer(lightsensor.getLightPercent()));
            dataLightOn.removeFirst();
         }
      }, delay, period);
   }
}


That's my code. The light never turns off. Anyone know what's going on? Does the passivate() method just not work?

roger
Moderator
Posts: 372
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA

passivate() method in Light doesn't work

Postby roger » Tue Jun 12, 2007 7:53 pm

because the passivate() is only implemented for the RCX style light sensors.
See the API for the LightSensor class. It uses setFloodlight(boolean floodlight)

Roger


Return to “NXJ Software”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest