How to make an image flash 120 beats per minute

49 views
Skip to first unread message
Assigned to chrisw...@gmail.com by me

Martial Foucault

unread,
Jul 6, 2019, 5:01:14 AM7/6/19
to MIT App Inventor Forum
Hi,
How to make an image flash 120 beats per minute.
I dont know how to configure that 
Thanks a lot

Chris Ward

unread,
Jul 6, 2019, 6:02:55 AM7/6/19
to MIT App Inventor Forum
Hi Martial

Depends on what an Image flash actually is, but hopefully you can modify the code below to suit your requirements. Project File "Image_Flash.aia" attached.

Flash_Image_Blocks.png









Image_Flash.aia

TimAI2

unread,
Jul 6, 2019, 6:15:46 AM7/6/19
to MIT App Inventor Forum

Martial Foucault

unread,
Jul 6, 2019, 7:46:18 AM7/6/19
to MIT App Inventor Forum
OOhh that's a great starting point. you're so quick

I have some difficulties to know how to organise the code

If I want 5 buttons with each one a specific BMP, is the best way to copy the block "When Button_1 clic" and change the name of the button and the divide operation ?
Or there is a simpler way to do that ?

I don't want a long code if i can do it shorter

Thank

TimAI2

unread,
Jul 6, 2019, 8:03:02 AM7/6/19
to MIT App Inventor Forum
You could use a listpicker with a selection of beats per minute listed
User picks one, then use the after picking event to set things in motion

Martial Foucault

unread,
Jul 6, 2019, 8:09:01 AM7/6/19
to MIT App Inventor Forum
yes the list picker can be an option, but I need something really simple => push a button and the picture blinks

Chris Ward

unread,
Jul 6, 2019, 8:18:45 AM7/6/19
to MIT App Inventor Forum
Hi Martial

I think a List View or List Picker would be easy to use. If you only require a few selections, you can do it with buttons, something like this (untested!):

Multiple Buttons.png


Right-click on the above image and select "open image in new tab" to view it full scale, with mouse zoom.


See attached Project File "Image_Flash_02.aia"


Image_Flash_02.aia

Chris Ward

unread,
Jul 6, 2019, 8:30:38 AM7/6/19
to MIT App Inventor Forum
Actually, the Stop Button should be in the Timer Block too, otherwise it simply won't work! (slaps head)

Modified:

Multiple Buttons 03.png


See the attached Project " Image_Flash_03.aia"

Image_Flash_03.aia

Martial Foucault

unread,
Jul 6, 2019, 10:11:00 AM7/6/19
to MIT App Inventor Forum
That's work like a charm.

How can I indicate to change the button color when selected, I tried with "when button .click " but it don't change to its original color when I click other button

Angel M

unread,
Jul 6, 2019, 1:09:13 PM7/6/19
to MIT App Inventor Forum

TimAI2

unread,
Jul 6, 2019, 1:14:05 PM7/6/19
to MIT App Inventor Forum
You need to set the button colour to 0 or -1 (can't remember which) to get back to the standard button colour.

Chris Ward

unread,
Jul 6, 2019, 1:56:38 PM7/6/19
to MIT App Inventor Forum
Hi Martial

We already have an If - ElseIf to know which is the Active Button, so we can just set it's colour there. Just before, set all buttons back to their normal colour:

Multiple Buttons 04.png


See the attached Project " Image_Flash_04.aia"


Image_Flash_04.aia

Martial Foucault

unread,
Jul 6, 2019, 3:33:00 PM7/6/19
to MIT App Inventor Forum
Thanks Chris, i don't know how much time I need to find and organize project like you do :))

I have one doubt, for exemple, when I chose the button 120, the image is shown each 2 beats, One beat visible, one beat invisible. So in fact the image beats 60 BPM.
Is it right ?
Hope I'm clear

TimAI2

unread,
Jul 6, 2019, 5:17:45 PM7/6/19
to MIT App Inventor Forum
Correct, selected bpm needs to be multiplied by 2

bpm.png


Chris Ward

unread,
Jul 6, 2019, 6:35:27 PM7/6/19
to MIT App Inventor Forum
Hi Martial

You and Tim are right :)

What we have (Image_Flash_04 example)  is one minute divided by required beats per minute - since it is hard coded, you can just change the BMP number in the "when any Button .Click" block:

Beats per Minute.png


Reply all
Reply to author
Forward
0 new messages