Go Down

### Topic: play sounds in steps and back.. (Read 391 times)previous topic - next topic

#### Nataschabakker

##### Jun 29, 2018, 10:49 am
Hi everyone,

I actually have quite a challenge, who can help me with this?
For a boy, I once made a speed cabinet with LCD for his lego funfair but he is nearsighted / ill and now it seemed nice to me to add sound but in steps, back and forth. Depending on speed, if it starts from 0 to for example 20 or 25% (0-30), then starting.wav can be played, it moves up to 60% than speed up.wave, but also down. Can this be realized? Is that possible? If so how?

It would be crazy if this works, example schedule

If the percentage goes from 0 to 30 percent, it must start.wav
If the percentage goes from 30 to 60 percent then play speedup.wav
From 60 to 100% fullspeed.wav

But if he goes back from 100% speed to 60% then speeddown.wav
From 60 to 30% speedroad.wav
Switch from 30% to 0% motoroff.wav

Code: [Select]
`/*  Testing speed with display and audio.*/#include <Wire.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27, 16, 2);#include <SMARTWAV.h>     //include the SMARTWAV library!SMARTWAV sWav;            //create our object called sWAV (smartWAV)int potPin = A0;int potValue = 0;int potValue1 = 0;int potValue2 = 0;const int tip = 6;void setup() {  pinMode(tip, OUTPUT);  lcd.init();    for (int i = 0; i < 3; i++)  {    lcd.backlight();    delay(50);    lcd.noBacklight();    delay(50);  }  lcd.backlight(); }void loop() {  // read the potentiometer, convert it to 0 - 255:  potValue = analogRead(potPin) / 5;  // use that to control the transistor:  analogWrite(tip, potValue);  // read then divide the input(max 1020 in this case) by 10  potValue1 = analogRead(potPin) / 10;  // divide by 1.02 to get percentage  potValue2 = potValue1 / 1.02;  // set cursor to second row, first column  lcd.setCursor(0, 1);  //display final percentage  lcd.print(potValue2);  //print the percent symbol at the end  lcd.print("%");>>>>>>>> how where  sWav.playTrackName("start");>>>>>>>> how where  sWav.playTrackName("speedup");>>>>>>>> how where  sWav.playTrackName("fullspeed");}`

Can someone help me with this?

Thanks allot

#### Nataschabakker

#1
##### Jun 29, 2018, 11:45 am
Hi everyone,

I actually have quite a challenge, who can help me with this?
For a boy, I once made a speed cabinet with LCD for his lego funfair but he is nearsighted / ill and now it seemed nice to me to add sound but in steps, back and forth. Depending on speed, if it starts from 0 to for example 20 or 25% (0-30), then starting.wav can be played, it moves up to 60% than speed up.wave, but also down. Can this be realized? Is that possible? If so how?

It would be crazy if this works, example schedule

If the percentage goes from 0 to 30 percent, it must start.wav
If the percentage goes from 30 to 60 percent then play speedup.wav
From 60 to 100% fullspeed.wav

But if he goes back from 100% speed to 60% then speeddown.wav
From 60 to 30% speedroad.wav
Switch from 30% to 0% motoroff.wav

Code: [Select]
`/*  Testing speed with display and audio.*/#include <Wire.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27, 16, 2);#include <SMARTWAV.h>     //include the SMARTWAV library!SMARTWAV sWav;            //create our object called sWAV (smartWAV)int potPin = A0;int potValue = 0;int potValue1 = 0;int potValue2 = 0;const int tip = 6;void setup() {  pinMode(tip, OUTPUT);  lcd.init();    for (int i = 0; i < 3; i++)  {    lcd.backlight();    delay(50);    lcd.noBacklight();    delay(50);  }  lcd.backlight(); }void loop() {  // read the potentiometer, convert it to 0 - 255:  potValue = analogRead(potPin) / 5;  // use that to control the transistor:  analogWrite(tip, potValue);  // read then divide the input(max 1020 in this case) by 10  potValue1 = analogRead(potPin) / 10;  // divide by 1.02 to get percentage  potValue2 = potValue1 / 1.02;  // set cursor to second row, first column  lcd.setCursor(0, 1);  //display final percentage  lcd.print(potValue2);  //print the percent symbol at the end  lcd.print("%");>>>>>>>> how where  sWav.playTrackName("start");>>>>>>>> how where  sWav.playTrackName("speedup");>>>>>>>> how where  sWav.playTrackName("fullspeed");}`

Can someone help me with this?

Thanks allot

I also think that the trick is to let them know if the value goes up and then play a file and know when the value goes down.

#### slipstick

#2
##### Jun 29, 2018, 04:54 pm
Basically you just need to remember what the last track was that you started playing and what the percentage is now. From that you can work out if it's going up or down and so what you might want to play next.

You need a bit more detail on the specification though. You've outlined the easy things but e.g. if the percentage goes up to 50 so you're playing "speedup" what is supposed to happen if it next goes down to 25? If you go from 100 to 60 then back to 100 what happens? And you'll want to put some hysteresis / dead bands in because you don't want to keep changing the track if the percentage hovers around between say 58 and 62.

Steve

#### Nataschabakker

#3
##### Jun 29, 2018, 11:36 pmLast Edit: Jun 30, 2018, 12:48 am by Nataschabakker
Hi Steve

Thank you for your reaction, okay that sounds logical, but how do I do that in practice?

What you say is true, maybe it is not entirely clear yet, because what should it do if it goes up halfway in speed while it is being phased out. That is in practice to figure out what the audio card does but what it should do:

Up with the speed
If percent goes from 0 to 30, or ends up in it somewhere, he can play start.wav
Speed ​​up and ends up between 30 and 60 percent than he can accelerate.wav playing
If he comes in speed between 60 and 100 percent, he can play fullspeed.wav

Down with the speed
From 100 percent down to 60 percent speedown.wav
From 60 percent down to 30 percent speedroad.wav
Between 30 percent and 0 than mottorgoingoff.wav

But if he goes down with the speed and he comes at 50 percent, so between 60 percent and 30 percent hey play speedroad.wav and one turns the potentiometer to increase the speed again, he may speed up back to the first up wav file. fullspeed.wav

Speed ​​up
0-30> start.wav
30-60> speedup.wav
60-100> fullspeed.wav

Speed ​​down
100-60> speedown.wav
30-0> motorgoingoff.wav

Full speed up 100> is full speed.wav down to 0 percent motorhomeoff.wav
Speed down to 50 percent he play speedroad.wav and pul it back up to 100 percent speed he play fullspeed.wav

If I know how this can be put in, then it is a matter of looking at what the audio card is going to do in practice.

Hope it is so clear, if that is not the case then I would like to hear it then I explain it again

Or maybe it's better to try out a somewhat easier way first? Well that's easy, because I do not understand it very well. maybe an idea if the speed goes up then you play speedup.wav and if the speed goes down you play speeddown.wav, when the speed again goes up when speeddown.wav is playing, break it and plat speedup.wav?

Thanks again

#### slipstick

#4
##### Jun 30, 2018, 12:53 am
I'd get the basics out of the way first. If you haven't already done this start by checking that you can successfully play a chosen wav. Then add that to your current program keeping it simple, perhaps just playing one sound when the speed is below 50% and another if it is over 50%.

How long does each sound last? Do they have to repeat? Or do you only check for a new speed when the sound that is playing has finished? It's an interesting project but it could be quite complicated to get right.

Steve

#### Nataschabakker

#5
##### Jun 30, 2018, 01:29 amLast Edit: Jun 30, 2018, 01:35 am by Nataschabakker
It is just what the practice does.
The card works, I can do it with a command
sWav.playTrackName ("start");
successfully playing a track, have worked with this audio card more often and that's fine.

What I run into is, how do I tell arduino when the speed rises and with that a wav playing and how do I know when the speed goes down, that calculation and translation I do not understand.

First the wav file will need to play once, if in practice it appears that this can be a loop, then it can be modified later on, even the audio files can be adjusted properly (studio) that is not the problem.

To be able to do the first tests, how to translate when the speed goes up and an audio wav sWav.playTrackName ("start"); and when he goes down in speed ....

#### slipstick

#6
##### Jun 30, 2018, 12:00 pm
The code you posted already calculates the speed as a percentage as 'potValue2'. So start by playing your startup wav and note the calculated speed when it started playing. Then keep checking the speed each time round loop() against that saved speed. It's easy to tell if it is going up or down. Then you just need to check what range it is in. Give it a try and post it here and if you have problems we can sort it out.

Steve

#### Nataschabakker

#7
##### Jul 03, 2018, 10:29 amLast Edit: Jul 03, 2018, 10:32 am by Nataschabakker
Oke, its working with this code.
Step upwards, so when the speed is going up and percent is
between 0 - 30 then hey plays myDFPlayer.playFolder(2, 1); (that is file 1 in folder 2).
When the speed is between 30-60 hey plays  myDFPlayer.playFolder(2, 2); (that is file 2 in folder2).
And the last one when speed is between 60-100 upwards hey plays  myDFPlayer.playFolder(2, 3); (that is file 3 from folder 2)

So thats working already. But now, when we turn the speed lower and comes between 30-60, he plays now again     myDFPlayer.playFolder(2, 2); but he must play a other because the speed is going down.
Lets say, hey must play     myDFPlayer.playFolder(2, 4); file 4 from folder 2.

But when we can fix it when he play     myDFPlayer.playFolder(2, 4); and we turn the speed again UP to 100% he must playing     myDFPlayer.playFolder(2, 3); upwards again, because teh speed is going upwards

Thats to difficule from, can someone explain me, where trick is?

Code: [Select]
`/*  Testing speed with display and audio.*/#include "LiquidCrystal_I2C.h"#include "SoftwareSerial.h"#include "DFRobotDFPlayerMini.h"SoftwareSerial mySoftwareSerial(2, 3); // RX, TXDFRobotDFPlayerMini myDFPlayer;LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);int potPin = A0;int potValue = 0;int potValue1 = 0;int potValue2 = 0;const int tip = 6;const int ledPin7 =  7;void setup() {  lcd.begin(20, 4);  pinMode(tip, OUTPUT);  for (int i = 0; i < 3; i++)    lcd.clear();}void loop() {  // read the potentiometer, convert it to 0 - 255:  potValue = analogRead(potPin) / 5;  // use that to control the transistor:  analogWrite(tip, potValue);  // read then divide the input(max 1020 in this case) by 10  potValue1 = analogRead(potPin) / 10;  // divide by 1.02 to get percentage  potValue2 = potValue1 / 1.02;  // set cursor to second row, first column  //display final percentage  lcd.setCursor(0, 2);  lcd.print(potValue2);  //print the percent symbol at the end  lcd.print("%");  if (potValue2 >= 10 && potValue2 <= 30)  {    myDFPlayer.playFolder(2, 1);  }  else if (potValue2 >= 30 && potValue2 <= 60)  {    myDFPlayer.playFolder(2, 2);  }  else if (potValue2 >= 60 && potValue2 <= 100)  {    myDFPlayer.playFolder(2, 3);  }}`

#### Nataschabakker

#8
##### Jul 03, 2018, 03:49 pm
I think, i have found a answer in a topic before, but this topic  doens't aprove is it working, i have this code to try the backwards (speed going down) but doesn't work http://forum.arduino.cc/index.php?topic=98468.0

Go Up