Button Touch up/ Touch down like volume increase decrease

106 views
Skip to first unread message

Jaqueline

unread,
Mar 1, 2018, 3:01:20 AM3/1/18
to mitappinv...@googlegroups.com
Hello,

I want to create a button with 2 functions:
1. When touched up, the morse code vibration and audio sound speed gets faster (SPEED of the player NOT VOLUME)
2. When touched down, the morse code vibration and audio sound speed gets slower (SPEED of the player NOT VOLUME)

Explanation:
I have an application that convert the text to morse code, so I get: "Hi" --> ".... .."  and after this conversion it play sound which is ".... .." correspondent.  I've settled the vibration intensity and the sound speed at a static parameter but I want that it be flexible so that if a user want to listen faster he can  touch up and voila it goes faster. 
I have uploaded to the player 1 mp3 file and I've created 3 procedures.  1st for "." at 50ms 2nd for "-" at 80ms and 3rd for " " at 100ms. (timing is an example).  I want the speed goes faster or slower.

Thank you in advance,

up.PNG
up1.PNG

Ghica

unread,
Mar 1, 2018, 8:59:12 AM3/1/18
to MIT App Inventor Forum
How did that delay thing get in there???? PLEASE read this:
The ONLY way to wait in App Inventor is to use a clock and a Timer event block.
Search this forum, there are plenty of examples.
Cheers, Ghica.

Jaqueline

unread,
Mar 2, 2018, 1:35:27 AM3/2/18
to MIT App Inventor Forum
I found this one did by someone :)
I just changed the count number and used it 

Ghica

unread,
Mar 2, 2018, 2:01:20 AM3/2/18
to MIT App Inventor Forum
DeLay or wait pops up quite frequently, but always because it does not work. App Inventor cannot do synchronous waiting like this. It will choke or freeze.
So, use a clock!
Cheers, Ghica

Jaqueline

unread,
Mar 2, 2018, 2:32:50 AM3/2/18
to MIT App Inventor Forum
Ok Ghica, but I need help with the speed fast/slow button.
Can you provide me some guide please
Thank you

TimAI2

unread,
Mar 2, 2018, 3:57:41 AM3/2/18
to MIT App Inventor Forum
Do you want to speed up the playback of the dots and dashes or simply reduce the gap between them?

Is a whole character created as one sound file, e.g. S = ... or using individual dots/dashes e.g. S= "."+"."+"." (three sound files) ?

You will reach a point where the player will not be able to keep up / playback any faster. Depends on how slow you start with.

If reducing the gaps, then just have a silent sound files of different lengths, and program the faster/slower buttons to select these, either the gaps between dots/dashes or between characters

Jaqueline

unread,
Mar 2, 2018, 4:18:56 AM3/2/18
to mitappinv...@googlegroups.com
Hello Tim,

Every person has a speed at which he feels perfect.  So starting from this opinion I want to make the speed of the morse code audio sound to be slow or fast(variable).  
I am using a single mp3 file (1 file only).

I don't know how to do it to work as the phone's volume key.  Maybe we can start from level 1 to have a maximum 5 and get a vibration when going up to 6.  Right now it is working as a static value.  Nobody can change it according to there satisfaction need.  I want it to be flexible.

Please I need help.  I know that it doesn't need any extension or something that does not exist yet on MIT APP INVENTOR. Can you please explain the silent sound file solution.  I didn't get it very well.  I want to include a button and when touched up do increase to a maximum of 5 and when down minimum 0 or 1. 

I will appreciate your help.
Thank you in advance

Ghica

unread,
Mar 2, 2018, 4:45:39 AM3/2/18
to MIT App Inventor Forum
Hi Jaqueline,
In your example you use vibrate, and not an mp3 file. To note about vibrate is that you cannot control the volume from your app, and you cannot stop the vibration once started.
If you want a solution with vibrate, then this is one, that I pulled from my morse app made earlier:


As you will note, everything is fixed here, but you can make it flexible by replacing all constants with a multiplication factor, like this:

If you replace all millisecond values in the nextsound procedure like this, it will adjust the length of the vibrations, but very important, also the length of the silence between vibrations. I carefully researched what the proportion of these lengths should be at websites about morse code, when I made that app.

I think you must be careful to change the speed at unexpected moments, because you would not be able to distinguish a dash from a dot anymore.

If you would want to use an mp3 file, you could take one that has a really long beep, and instead of saying vibrate for so many milliseconds, set a timer interval for a second clock and start the player with that long mp3 ile. At the timer event for that second clock you could stop the player and disable that clock. I do not know how accurate that would be.

Cheers, Ghica.

Jaqueline

unread,
Mar 2, 2018, 5:01:36 AM3/2/18
to mitappinv...@googlegroups.com
Hello Ghica,

Thank you for helping me every time and guiding me to the right path.
I guess what you provided in the screenshots is the best way to work with morse code and vibration and I am going to correct it and implement your blocks instead of using delay many times.

What concerns the vibration speed,  actually you are right it is not possible to stop the vibration and the volume increase.  I want to make it faster, it shouldn't be more strong or high volume vibration just to be faster.  Yes you are also right that at a point it wouldn't be possible to recognize the difference between dot and dash because it will be going to fast, so maybe I will limit the user to a specific value for example: minimum 10 and maximum 50.  Below 10 not possible and above 50 as well.  

WHEN BUTTON.TOUCH-UP {
                   INCREASE.VOLUME(10);
}

WHEN BUTTON.TOUCH-DOWN {
                   DECREASE.VOLUME(10);
}

so it will go up 10 by 10 and down 10 by 10.  And that speed has to be applied as default until the user change it again.   

Hope I was able to explain what I need for that button up/down.

Ghica can you upload the aia file of this screenshot please.

Thank you in advance,

Ghica

unread,
Mar 2, 2018, 6:49:56 AM3/2/18
to MIT App Inventor Forum
Hi Jaqueline,
Instead of increase/decrease volume, you ment increase/decrease speed?
And, are you going to settle for vibration or do you want to use mp3 after all?

And, think of clicking a button:
When you click on it, you will get a touch-down event, you could decrease the speed then. But necessaily you will get a touch up event after that, and if you increase by the same amount, the speed will be what it was before.
Conclusion: you cannot do what you want with one button. You could use two buttons, one for increase and one for decrease. You could also use a slider and set its min and max values. When the slider position changes, you will also get an event and you can set the speed at whatever the slider position is.

Cheers, Ghica.

Jaqueline

unread,
Mar 2, 2018, 7:09:10 AM3/2/18
to MIT App Inventor Forum
Hello Ghica,

I am using audio beep sound and vibration at the same time.  I want increase/decrease the speed of these so that the user can set it as he feels best for him.  Maybe I can read the morse code in level 3 speed (takes 2 minute to convert and sound "hi how are you" in morse) and you in level 5 (takes 1 mint only) so in this way you won't be obliged to wait 1 minute extra because the application is at a static speed.  This is the purpose of what I am trying to do.

Okay Ghica, I am going to try the slider.   I didn't use it before, this is going to be the first time and I am very excited to learn new things :)

Thank you in advance


Ghica

unread,
Mar 2, 2018, 7:28:36 AM3/2/18
to MIT App Inventor Forum
At least initially, you should settle for either vibration or mp3 sound. Only when you have one workeng try to add the other.
Because it is easier, I would advise to try vibrate first.
Cheers, Ghica.

Jaqueline

unread,
Mar 2, 2018, 7:43:37 AM3/2/18
to MIT App Inventor Forum
okay Ghica,

I am going to try it, I am reading about the slider now.  I will try to use it and do it.  If I've got any question, I will ask you.

Thank you Ghica :)

Jaqueline

unread,
Mar 3, 2018, 4:03:45 AM3/3/18
to MIT App Inventor Forum
Hello Ghica,

I was trying to correct my blocks according your screenshots before working on the slider.  I am always getting error starting from number 0 etc.
Can you please provide the aia file I guess I am doing something wrong.

Thank you in advance

Ghica

unread,
Mar 3, 2018, 5:12:36 AM3/3/18
to MIT App Inventor Forum
Jaqueline,
The .aia is in the other thread about Morse conversion.
You could also show your blocks and the error message you are getting.
Cheers, Ghica

Jaqueline

unread,
Mar 5, 2018, 2:02:59 AM3/5/18
to mitappinv...@googlegroups.com
Hello Ghica,

I changed my blocks to what you provided as screenshots.  Of course, they are the best way to do the conversion from alphabet to morse.  And I added the slider, (vertical slider extension).  Just I wanted to ask, to be able to continue from the right to the right way, for the speed should I create a procedure and call it or just add if else conditional in the clock timer?
For example, IF slider value = 100 speed 150, else if slider value = 150 speed 200 etc ...

Thank you in advance

Ghica

unread,
Mar 5, 2018, 6:23:23 AM3/5/18
to MIT App Inventor Forum
No and no.
Define a global variable called speed. Change in the nextSound procedure and in Clock1.Timer ALL blue math numbers that define milliseconds to vibrate and the timer interval for the clock into a multiplication block where you multiply the value with speed. I gave an example of that.
Set speed initially to 1 and see if it still works. If yes, change speed to 0.5 or 2 using DoIt and try again. Play a bit with the minimum and maximum values you want to have. 
If you found that out, ste the min and max values of the slider to what you want and use the when.Slider position changed event block to set the speed in the global variable speed. That should be all. 
It could be possible that the sound gets the hiccups changing the slider position, in that case you could set global speed to thumbposition in either clock.Timer, or nextSound (but not both) instead.
Cheers, Ghica.
 

Jaqueline

unread,
Mar 6, 2018, 5:07:49 AM3/6/18
to MIT App Inventor Forum
Hello Ghica,

I've done as you said.  It is working well.

Thank you Ghica :)

Ghica

unread,
Mar 6, 2018, 5:29:37 AM3/6/18
to MIT App Inventor Forum
Great! Cheers, Ghica
Reply all
Reply to author
Forward
0 new messages