Skip to first unread message

pavankumar kavvuri

unread,
Dec 29, 2015, 12:31:45 PM12/29/15
to MIT App Inventor Forum
I need to send the series of same byte number upon long pressing the button until I release it.
But using long press event can only send one of it. I hope that using clock timer may yield any desired result. I am still working on that.
I hope that you people could fix this.


Thanks in advance!!!

Regards,
PavanKumar k

Scott Ferguson

unread,
Dec 29, 2015, 12:50:53 PM12/29/15
to MIT App Inventor Forum
There is nothing to fix.
The event is intended to trigger once.
Your suggestion of using a Clock Timer to continue processing is right on.
That is what I would do as well.
---
sf

Abraham Getzler

unread,
Dec 29, 2015, 6:29:57 PM12/29/15
to MIT App Inventor Forum
On the long press, set a global variable to how many times your byte value should be sent,
and start the clock timer.

Each time the clock fires, check if the global is > 0.
If >0, subtract 1 from it and emit a byte.
If <= 0, disable the timer.

ABG

pavankumar kavvuri

unread,
Dec 30, 2015, 10:34:48 PM12/30/15
to MIT App Inventor Forum
Sir, I have implemented what you have said. Although I discovered a new thing for me but I didn't get what I desire. My doubt is, can we calculate the time we hold the button in App inventor. If it is so my problem is solved. Unlike you have said, I don't need to declare in prior how many times it should looping ! since I am working with stock of buttons, others don't respond til the loop ends.
I hope you understand. I just attached the file.

Thanks in advance!!!

Regards,
PavanKumar K



Capture.PNG

Abraham Getzler

unread,
Dec 30, 2015, 10:51:13 PM12/30/15
to MIT App Inventor Forum
To get tight timing some people use sprites on a canvas
for buttons, to tale advantage of the touch up and
touch down events.  

If you prefer buttons, there is another alternative to
long press.  If you set the text of the button alternately
to START or STOP, you can use the button to do both,
changing the button text after each click.

sample blocks:

when btnStartSTop.Click,
if btnStartStop.Text = "Start" then
   call Start 
   set btnStartStop.Text to "Stop"
ELSE
   call Stop
   set btnStartStop.Text to "Start"
end if

ABG

Abraham Getzler

unread,
Dec 30, 2015, 10:53:37 PM12/30/15
to MIT App Inventor Forum
If you use either of my ideas in my last post,
you don't need the global time counter.
Just let the clock repeat until you need to stop it.

ABG

pavankumar kavvuri

unread,
Dec 30, 2015, 11:11:27 PM12/30/15
to MIT App Inventor Forum
But how could I calculate the time I hold the button. 
My idea is to set the timer to the time I hold each button.



Thank you!!


Regards,
PavanKumar K

Abraham Getzler

unread,
Dec 31, 2015, 12:37:42 PM12/31/15
to MIT App Inventor Forum
See attached sample.

When Button1 TouchDown, I store the current
milliseconds since 1970 in Label1.Text.
When Button1.TouchUp, I subtract the current
milliseconds since 1970 from the Label1.Text value,
to get the milliseconds that Buttton1 was held down,
and store it in Label1.Text.

Button2 and Label2 are not wired, just to 
remind us that we can do this with multiple buttons,
though not necessarily simultaneously.

For your app, you would use a global variable or two
for the temporary interval value.

ABG

Button1.png
ButtonTime.aia
Emulator.png
Reply all
Reply to author
Forward
0 new messages