Button.LEDPattern()

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

Moderators: roger, gloomyandy, skoehler

Button.LEDPattern()

Postby tigger » Mon Feb 10, 2014 10:16 pm

Currently, the API doc is not really comprehensive.

Here a quick demo what arguments accpepted by the method Button.LEDPattern

Code: Select all
import lejos.hardware.Button;
import lejos.hardware.lcd.LCD;

public class ButtonLights {

   public static void main(String[] args) {
      new ButtonLights().start();
   }

   private boolean finished;
   private int pattern;

   public void start() {
      finished = false;
      pattern = 0;
      refreshDisplay();
      Thread buttonListener = new Thread() {
         public void run() {
            while(!finished) {
               buttonPressed(Button.waitForAnyPress());
            }
            Button.LEDPattern(0); // don't forget to turn off light before exit
         }
      };
      buttonListener.setDaemon(true);
      buttonListener.start();
      while(!finished) {
         Thread.yield();
      }
   }

   private void buttonPressed(int buttonId) {
      switch (buttonId) {
      case Button.ID_ESCAPE:
         finished = true;
         break;
      case Button.ID_UP:
         ++pattern;
         refreshDisplay();
         break;
      case Button.ID_DOWN:
         if (pattern > 0) {
            --pattern;
            refreshDisplay();
         }
         break;
      }
   }
   
   private void refreshDisplay() {
      LCD.clear();
      LCD.drawString("BUTTON LIGHTS", 0, 0);
      LCD.drawString(" UP:     next", 0, 1);
      LCD.drawString(" DOWN:   back", 0, 2);
      LCD.drawString(" ESCAPE: exit", 0, 3);
      LCD.drawString("-------------", 0, 4);
      LCD.drawString("Pattern: " + pattern, 0, 5);
      Button.LEDPattern(pattern);
   }
}


0: turn off button lights
1/2/3: static light green/red/yellow
4/5/6: normal blinking light green/red/yellow
7/8/9: fast blinking light green/red/yellow
>9: same as 9.

NOTE: Interrupting this demo with DOWN+ENTER will keep lights on with current pattern. Funny :)

EDIT: Move Button.LEDPattern(0); into thread to turn off lights on program end.
tigger
New User
 
Posts: 17
Joined: Mon Feb 10, 2014 10:04 pm

Re: Button.LEDPattern()

Postby lawrie » Tue Feb 11, 2014 6:36 pm

I should have fixed switching off the LED when you return tothe menu, in the 0.6.0-alpha release, which is now out.
lawrie
leJOS Team Member
 
Posts: 909
Joined: Mon Feb 05, 2007 1:27 pm

Re: Button.LEDPattern()

Postby tigger » Tue Feb 11, 2014 8:14 pm

Next release - yeah!

By the way: hail to the whole crew porting leJOS with all its features and possibilities to EV3! Great job, guys!
tigger
New User
 
Posts: 17
Joined: Mon Feb 10, 2014 10:04 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

cron
more stuff