... | ... | @@ -57,7 +57,7 @@ The telephone plays a sine tone at 100 percent volume. We then moved the sound s |
|
|
|
|
|
|
|
|
#### Conclusion
|
|
|
|
|
|
We tested the sound sensor with different kind of sound sources - our voices and a sine tone from a phone. The sensor seemed to respond more towards our voices, which had some effect on the test. If we were to do the test again it would be beneficial to do it in a soundproof room where we would not speak at all during the test , then it would properly result in more accurate test data.
|
|
|
|
|
|
### Exercise 3 - Sound Controlled Car
|
|
|
|
... | ... | @@ -86,25 +86,36 @@ We are planning to do this by looking at the leJos tutorial[1] on how to use a B |
|
|
|
|
|
#### Results
|
|
|
```
|
|
|
public class SoundCtrCar
|
|
|
{
|
|
|
private static int soundThreshold = 90;
|
|
|
private static SoundSensor sound = new SoundSensor(SensorPort.S1);
|
|
|
|
|
|
private static void waitForLoudSound() throws Exception
|
|
|
Thread.sleep(250);
|
|
|
do
|
|
|
{
|
|
|
if ( Button.ESCAPE.isDown()){
|
|
|
System.exit(0);
|
|
|
}
|
|
|
soundLevel = sound.readValue();
|
|
|
LCD.drawInt(soundLevel,4,10,0);
|
|
|
}
|
|
|
while ( soundLevel < soundThreshold );
|
|
|
```
|
|
|
##### CodeSnip1: This shows a snippet of our implemented code.
|
|
|
-
|
|
|
|
|
|
```
|
|
|
private static void waitForLoudSound() throws Exception
|
|
|
{
|
|
|
int soundLevel;
|
|
|
Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
int soundLevel;
|
|
|
|
|
|
Button.ESCAPE.addButtonListener(new ButtonListener() {
|
|
|
public void buttonPressed(Button b) {
|
|
|
LCD.drawString("escape pressed", 0, 0);
|
|
|
System.exit(0);
|
|
|
|
|
|
}
|
|
|
public void buttonReleased(Button b) {
|
|
|
LCD.clear();
|
|
|
running = false;
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
##### CodeSnip1: This shows a snippet of our implemented code.
|
|
|
##### CodeSnip2: This shows a snippet of the code that did not work.
|
|
|
-
|
|
|
|
|
|
|
... | ... | @@ -112,7 +123,9 @@ public class SoundCtrCar |
|
|
##### Video2: robot running implemented code.
|
|
|
|
|
|
#### Conclusion
|
|
|
As seen in the above code snippet we implemented a ButtonListener that didn't interfere with anything else.
|
|
|
As seen in the above code snippet we implemented a if sentence that listens for if the escapebutton is down. The if-sentence is implemented in the do-while loop in the method waitforloudsound(). If the escape button is pressed down, then it exits the program. The code working is seen above in CodeSnip1.
|
|
|
We also tried implementing a button listener as seen in CodeSnip2, although, when using this code and running the program soundctrlcar, it throws an exception after 3 high noises. We don’t know why this happened, so we ended up using the if-sentence described in CodeSnip1.
|
|
|
|
|
|
|
|
|
### Exercise 5 - Clap Controlled Car
|
|
|
|
... | ... | @@ -139,6 +152,7 @@ We are going to do this by using the the raw-value from the sensor, for better p |
|
|
|
|
|
[![image alt text](http://img.youtube.com/vi/A6RI8WMmXpY/0.jpg)](https://www.youtube.com/watch?v=A6RI8WMmXpY&feature=youtu.be)
|
|
|
##### Video3: Party Robot in action.
|
|
|
-
|
|
|
|
|
|
|
|
|
```
|
... | ... | @@ -169,15 +183,6 @@ public class TinesPartyRobot { |
|
|
if (yarn < -6) {
|
|
|
Car.forward(75, 0);
|
|
|
}
|
|
|
Thread.sleep(30);
|
|
|
}
|
|
|
Car.stop();
|
|
|
LCD.clear();
|
|
|
LCD.drawString("Program stopped", 0, 0);
|
|
|
Thread.sleep(2000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
```
|
|
|
##### CodeSnip2: This shows a snippet of our implemented Party Robot code.
|
|
|
|
... | ... | |