@@ -137,8 +137,52 @@ We are going to do this by using the the raw-value from the sensor, for better p
...
@@ -137,8 +137,52 @@ We are going to do this by using the the raw-value from the sensor, for better p
#### Results
#### Results
#### Conclusion
[](https://www.youtube.com/watch?v=A6RI8WMmXpY&feature=youtu.be)
##### Video3: Party Robot in action.
```
public class TinesPartyRobot {
private static SoundSensor micRight = new SoundSensor(SensorPort.S1);
private static SoundSensor micLeft = new SoundSensor(SensorPort.S2);
private static int leftMic;
private static int rightMic;
private static int yarn;
public static void main(String[] args) throws Exception {
while(!Button.ESCAPE.isDown()) {
rightMic = micRight.readValue();
leftMic = micLeft.readValue();
yarn = leftMic - rightMic;
//drive forward
if (Math.abs(yarn) <= 4) {
Car.forward(75, 75);
}
//turn left
if (yarn > 6) {
Car.forward(0, 75);
}
//turn right
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.
#### 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.