|
@@ -12,7 +12,7 @@ Grove_LED_Bar bar(5, 4, 0); // Clock pin, Data pin, Orientation
|
|
|
|
|
|
SoftwareSerial mp3(6, 7);
|
|
|
|
|
|
-int soundWaitTime = 20000;
|
|
|
+long int soundWaitTime = 120000;
|
|
|
long int front_lastplayed , down_lastplayed;
|
|
|
|
|
|
void setup()
|
|
@@ -26,9 +26,9 @@ void setup()
|
|
|
delay(100);
|
|
|
|
|
|
SelectPlayerDevice(0x02); // Select SD card as the player device.
|
|
|
- SetVolume(0x1E); // Set the volume, the range is 0x00 to 0x1E.
|
|
|
- front_lastplayed = -1*soundWaitTime;
|
|
|
- down_lastplayed = -1*soundWaitTime;
|
|
|
+ SetVolume(0x19); // Set the volume, the range is 0x00 to 0x1E.
|
|
|
+ front_lastplayed = -100000;
|
|
|
+ down_lastplayed = -20000;
|
|
|
}
|
|
|
|
|
|
void loop()
|
|
@@ -40,27 +40,29 @@ void loop()
|
|
|
int bar_level = map(down_distance, 0, 42, 10, 0);
|
|
|
bar_level = constrain(bar_level, 0, 10);
|
|
|
bar.setLevel(bar_level);
|
|
|
- Serial.println(bar_level);
|
|
|
+// Serial.println(bar_level);
|
|
|
long int currentTime = millis();
|
|
|
-
|
|
|
- if ( (bar_level > 8) && ((currentTime - down_lastplayed)>soundWaitTime) ) {
|
|
|
- SpecifyMusicPlay(1);
|
|
|
- Serial.println("Playing high level track");
|
|
|
- down_lastplayed = currentTime;
|
|
|
- }
|
|
|
-
|
|
|
- if ( (bar_level < 2) && ((currentTime - down_lastplayed)>soundWaitTime) ) {
|
|
|
- SpecifyMusicPlay(2);
|
|
|
- Serial.println("Playing low level track");
|
|
|
- down_lastplayed = currentTime;
|
|
|
+ if ( ((currentTime - down_lastplayed)>soundWaitTime) && (currentTime - front_lastplayed)>20000) {
|
|
|
+ if ( bar_level > 8 ) {
|
|
|
+ SpecifyMusicPlay(3);
|
|
|
+ Serial.println("Playing high level track");
|
|
|
+ down_lastplayed = currentTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( (bar_level < 2) && ((currentTime - down_lastplayed)>soundWaitTime) ) {
|
|
|
+ SpecifyMusicPlay(2);
|
|
|
+ Serial.println("Playing low level track");
|
|
|
+ down_lastplayed = currentTime;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
|
|
|
- if ( (front_distance < 100) && ((currentTime - front_lastplayed)>soundWaitTime) ) {
|
|
|
- SpecifyMusicPlay(3);
|
|
|
+ if ( (front_distance < 100) && ((currentTime - front_lastplayed)>soundWaitTime) && ((currentTime - down_lastplayed)>20000) ) {
|
|
|
+ SpecifyMusicPlay(1);
|
|
|
Serial.println("Playing proximity track");
|
|
|
front_lastplayed = currentTime;
|
|
|
}
|
|
|
-
|
|
|
+ delay(100);
|
|
|
|
|
|
|
|
|
long RangeInCentimeters;
|