-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathColorDemo.java
More file actions
85 lines (63 loc) · 2.05 KB
/
Copy pathColorDemo.java
File metadata and controls
85 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ev3.exercises;
import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.hardware.port.SensorPort;
import lejos.robotics.Color;
import lejos.utility.Delay;
import ev3.exercises.library.ColorSensor;
import ev3.exercises.library.Lcd;
public class ColorDemo
{
public static void main(String[] args)
{
ColorSensor color = new ColorSensor(SensorPort.S3);
System.out.println("Color Demo");
Lcd.print(2, "Press to start");
Button.LEDPattern(4); // flash green led and
Sound.beepSequenceUp(); // make sound when ready.
Button.waitForAnyPress();
Button.LEDPattern(0);
// run until escape button pressed.
while (Button.ESCAPE.isUp())
{
Lcd.clear(4);
Lcd.print(4, "ambient=%.3f", color.getAmbient());
Delay.msDelay(250);
}
Delay.msDelay(1000);
color.setRedMode();
color.setFloodLight(Color.RED);
color.setFloodLight(true);
while (Button.ESCAPE.isUp())
{
Lcd.clear(5);
Lcd.print(5, "red=%.3f", color.getRed());
Delay.msDelay(250);
}
Delay.msDelay(1000);
color.setRGBMode();
color.setFloodLight(Color.WHITE);
Color rgb;
while (Button.ESCAPE.isUp())
{
rgb = color.getColor();
Lcd.clear(6);
Lcd.print(6, "r=%d g=%d b=%d", rgb.getRed(), rgb.getGreen(), rgb.getBlue());
Delay.msDelay(250);
}
Delay.msDelay(1000);
color.setColorIdMode();
color.setFloodLight(false);
while (Button.ESCAPE.isUp())
{
Lcd.clear(7);
Lcd.print(7, "id=%s", ColorSensor.colorName(color.getColorID()));
Delay.msDelay(250);
}
// free up resources.
color.close();
Sound.beepSequence(); // we are done.
Button.LEDPattern(4);
Button.waitForAnyPress();
}
}