[ev3 × Java] Display, sound, LED control

This article is for anyone who wants to work with ev3 in Java. This time, I would like to use intelligent blocks to display text, make sounds, and control LEDs.

table of contents

  1. What to prepare
  2. Display
  3. Sound 3 . LED Finally

0. What to prepare

◯ ev3 (intelligent block) ◯ Personal computer (VS Code) ◯ bluetooth ◯ microSD ◯ API Documentation (It is recommended to proceed while watching this.)

1. Display

1-0. Basic display program ①

◯ It is a program that displays characters for 3 seconds.

display00.Java


import lejos.utility.Delay;

public class Display00
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!!");
        Delay.msDelay(3000);
    }
}

1-1. Basic display program ②

◯ It is a program that can change the place and font to display the text.

display01.java


import lejos.hardware.lcd.Font;
import lejos.hardware.lcd.GraphicsLCD;
import lejos.hardware.ev3.LocalEV3;
import lejos.utility.Delay;


public class Display01 {

    public static void main(String[] args) {

    	GraphicsLCD g = LocalEV3.get().getGraphicsLCD();
        final int SW = g.getWidth();
        final int SH = g.getHeight();
    	
		g.drawString("Hello World", 5, 0, 0);
		Delay.msDelay(3000);
		g.setFont(Font.getSmallFont());
		g.drawString("Programming is so fantastic!!", 2, 20, 0);
		Delay.msDelay(3000);
        g.drawString("Good BYE", SW/2, SH/2, 0);
		Delay.msDelay(1000);
    }
}

Point: ** drawString method ** void drawString(java.lang.String str,int x,int y,boolean inverted)


Point:Font


Point: ** Interface Graphics LCD **


1-2. Basic display program ③

◯ It is a program that displays figures.

display02.java


import lejos.hardware.lcd.GraphicsLCD;
import lejos.hardware.ev3.LocalEV3;
import lejos.utility.Delay;


public class Display01 {

    public static void main(String[] args) {

    	GraphicsLCD g = LocalEV3.get().getGraphicsLCD();
        final int SW = g.getWidth();
        final int SH = g.getHeight();
  
        g.drawChar('A', 30, 30, 0);
        g.drawRect(0,0,100,100);
        g.fillRect(SW/2,SH/2,50,50);
        Delay.msDelay(3000);
    }
}

Point:getGraphicsLCD Get graphics access to the LCD Returns:the graphics LCD

Point: ** drawRect method ** void drawRect(int x,int y,int width,int height)


2. Sound

2-0. Basic sound program ①

◯ It is a program that makes various sounds.

Sound00.java


import lejos.hardware.Sound;

public class Sound00
{
    public static void main(String[] args)
    {
        Sound.beep();
        Sound.buzz();
        Sound.systemSound(true,2);
    }
}

Point: ** Sound class methods **


2-1. Basic sound program ②

◯ It is a program that adjusts the frequency and produces sound.

Sound01.java


import lejos.hardware.Sound;

public class Sound01
{
    public static void main(String[] args)
    {
    	Sound.playTone(262, 500);//Do
    	Sound.playTone(294, 500);//Re
    	Sound.playTone(330, 500);//Mi
    	Sound.playTone(349, 500);//Fa
    	Sound.playTone(392, 500);//So
    }
}

Point: ** Scale frequency **

3.LED

3-0. Basic LED program

◯ Colors can be displayed in various patterns.

led00.java


import lejos.hardware.Button;
import lejos.utility.Delay;

public class LED00 {

    public static void main(String[] args) {

    	for (int i = 0;i < 10;i++) {
    		System.out.println(i);
    		Button.LEDPattern(i);
    		Delay.msDelay(3000);
    	}
    }
}

Finally

Thank you for reading! !! Next time, I would like to write about intelligent block buttons!

I want to make a better article ◯ This is easier to understand ◯ This is difficult to understand ◯ This is wrong ◯ I want you to explain more here We appreciate your opinions and suggestions.

Recommended Posts

[ev3 × Java] Display, sound, LED control
[ev3 x Java] Single motor control
Java control syntax
Java control syntax
[LeJOS] Let's control the EV3 motor with Java
[Java] Control syntax notes
[LeJOS] Let's remotely control the EV3 motor with Java
Java version control on macOS
[Java] Multi-thread processing --Exclusive control
Version control Java with SDKMAN
[Java] How to display Wingdings
Java version control with jenv
☾ Java / Iterative statement and iterative control statement
Seasonal display with Java switch
[Java] Summary of control syntax