... | ... | @@ -124,7 +124,7 @@ private static void waitForLoudSound() throws Exception |
|
|
|
|
|
#### Conclusion
|
|
|
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.
|
|
|
We also tried implementing a button listener as seen in CodeSnip2, although, when using this code and running the program soundCtrlCar.java[4], 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
|
... | ... | @@ -136,6 +136,46 @@ Our goal is to make a method, using Sivan Toledos method[2], that detects clap, |
|
|
We plan on writing the necessary code and use a Datalogger[3] to record the data and afterwards conclude on the pattern.
|
|
|
|
|
|
#### Results
|
|
|
The code we ended up implementing is seen below:
|
|
|
|
|
|
```
|
|
|
private static void waitForLoudSound() throws Exception
|
|
|
{
|
|
|
boolean clap = false; // setting a boolean to false, so when it does not hear a clap, it is false
|
|
|
|
|
|
Thread.sleep(500);
|
|
|
do
|
|
|
{
|
|
|
if ( Button.ESCAPE.isDown()){
|
|
|
System.exit(0); // exit the program if escape button is pressed down
|
|
|
}
|
|
|
int milliSeconds = (int)System.currentTimeMillis(); // sets the integer milliSeconds to the //current time the porgram has been running in milliseconds
|
|
|
LCD.drawInt(sound.readValue(),4,10,0);
|
|
|
|
|
|
if (sound.readValue() < 50 ){
|
|
|
while (milliSeconds + 25 >(int)System.currentTimeMillis()){
|
|
|
if (sound.readValue() > 85){ // if it reads a sound value above 85 within 25 //milliseconds then move onto the while-loop
|
|
|
milliSeconds = (int)System.currentTimeMillis();
|
|
|
while((milliSeconds+250)>(int)System.currentTimeMillis()){
|
|
|
if(sound.readValue() <50){
|
|
|
clap =true; // if it reads a sound value below 50 within 250 //milliseconds, then set clap to true, and execute the code in the method
|
|
|
}
|
|
|
LCD.drawInt(milliSeconds,4,10,3);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
while ( clap !=true ); // only do the while-loop if clap is not equal to true
|
|
|
}
|
|
|
```
|
|
|
##### CodeSnip3: This shows a snippet of interpretation of Sivan Toledos[2] method.
|
|
|
-
|
|
|
|
|
|
Below is our results from the samples taken through the datalogger. Both using our own code created from the clapping data from Sivan Toledo[2] and the results from the already created soundCtrCar.java[4]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### Conclusion
|
|
|
|
... | ... | @@ -184,7 +224,7 @@ public class TinesPartyRobot { |
|
|
Car.forward(75, 0);
|
|
|
}
|
|
|
```
|
|
|
##### CodeSnip2: This shows a snippet of our implemented Party Robot code.
|
|
|
##### CodeSnip4: This shows a snippet of our implemented Party Robot code.
|
|
|
|
|
|
#### Conclusion
|
|
|
The code we have implemented uses three steps; one for driving forward, one for driving left and for driving right. We subtract the two sound levels from the microphones, to see which one of the microphones that registres a higher sound level than the other. We store this new value in a variable and uses it to determine in which direction the robot should drive. If the variable is higher than 7 the robots turns right, if it lower than -7 the robot turns left, and if the value is positive and lower or equal to 7 the robot drives forward. The last step is implemented so that it drives forward when the two microphones registres almost the same level.
|
... | ... | |