Please Help Me Grock The Clock

Greetings, Everyone

Happy holidays. no matter your religious persuasion or lack thereof. I have been going over posts related to using a clock timer and I have come to the conclusion that I am missing something repeatedly and it is time to ask for a solution.

I am attempting to use a clock set at 500ms to update pitch and roll data on my app. I am including the clock settings and the way that it does not work first.

Clock_Properties

As I said, nothing happens and, if you see why . . . please, please tell me. Using the following block, I now have the pitch and roll displayed but the readout changes many times a second (slightly - by hundredths). This results in a phrenetic display that is hard to look at - So - I can display pitch and roll but not in the manner I desire.


This does the same thing . . .

Will someone please point out the error of my ways, here? Thank you.

The strange behaviour comes because you start the clock over and over as soon as the orientation sensor fires. Try this:
blocks (15)

1 Like

Alternatively:

This thead's experiment exposed some internal logic of how the AI2 clock component works.

There must be an internal countdown variable in the clock, inaccessible to us, where it keeps track of how many milliseconds until it should trigger the Timer event. (Unlike those TV bombs with the dramatic red LED 7 segment external countdown displays)

Whoever coded the Clock block that sets the .Enabled attribute to true must have added extra code to reset that internal counter so it will trigger the Timer n milliseconds in the future, according to the clock component milliseconds attribute.
It must be doing this without checking if the .Enabled attribute was already true.

Greetings Django, TIMA12, ABG, et al.

Thank you for the responses and suggestions. Given everything suggested, (and having no button to speak of,) I came up with the following solution that suits my needs.

I will play with this to better . . .
"Grock the Clock Block so I can Walk the Talk" because what ABG is alluding to sets my brain to "vibrate" mode.

Sounds for me a little bit like ChatGPT on drugs :smiley:

I am a bit late to chime in here but... because of my attempts to control a robot car using the orientation sensor, I think I have some experience. I had a picture of a compass on my phone and the robot car would go in the direction your phone was tilting at and the speed was controled by the amount of tilting.
I do not know what you are goig to use these values for, but for my purpose I switched to using the AccelerometorSensor, because it was easier to handle. But the principles of using them are very similar.

Anyway, I think it is a bad idea to ue both a timer and the OrientationSensor.
The OrientationSensor changes its values much too fast and chockes the phone display after a while. If you only use the clock, you can do with whatever the values are at ease.

So, I think @TIMAI2 Tim's solution is better than yours (why would you enable and disable the clock everytime, it does not add anything to your logic and you do not seem to use timer events). And also in his solotion I do not see what the use of having these global variables is, unless you are doing something with them asynchronously.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.