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.
◯ ev3 (intelligent block) ◯ Personal computer (VS Code) ◯ bluetooth ◯ microSD ◯ API Documentation (It is recommended to proceed while watching this.)
◯ 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);
}
}
◯ 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 **
◯ 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)
◯ 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 **
◯ 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
◯ 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);
}
}
}
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