Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LEGO Group 8
LEGO
Commits
8790edb0
Commit
8790edb0
authored
Mar 02, 2015
by
Casper
Browse files
Added src ClapControl
parent
ef43b3d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
lesson3/ClapControl/src/ClapControl.java
0 → 100644
View file @
8790edb0
import
lejos.nxt.*
;
public
class
ClapControl
{
static
ADSensorPort
soundSensor
=
SensorPort
.
S3
;
static
int
soundThreshold
=
85
;
static
int
clapCount
=
0
;
private
static
void
waitForClap
()
throws
Exception
{
int
soundLevel
;
double
timerStart
;
double
timerStop
;
double
diff
;
do
{
do
{
soundLevel
=
soundSensor
.
readValue
();
LCD
.
drawInt
(
soundLevel
,
4
,
10
,
0
);
}
while
(
soundLevel
<
soundThreshold
);
timerStart
=
System
.
currentTimeMillis
();
do
{
// Stopwatch running
soundLevel
=
soundSensor
.
readValue
();
LCD
.
drawInt
(
soundLevel
,
4
,
10
,
0
);
}
while
(
soundLevel
>
soundThreshold
);
timerStop
=
System
.
currentTimeMillis
();
diff
=
timerStop
-
timerStart
;
//LCD.drawInt((int)diff,4,10,1);
}
while
(
!(
25
<
diff
&&
diff
<
110
));
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
soundSensor
.
setTypeAndMode
(
SoundSensor
.
TYPE_SOUND_DB
,
SoundSensor
.
MODE_PCTFULLSCALE
);
while
(!
Button
.
ESCAPE
.
isDown
())
{
waitForClap
();
LCD
.
drawString
(
"Clap Count: "
+
clapCount
,
0
,
1
);
clapCount
++;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment