Share My Creation [B4X] A Not-So-Simple Clock

I appreciate the beauty of simplicity, and it is often the key to finding solutions, but it isn’t everything. I am often drawn to the ingenious creations of artists like Rube Goldberg and Heath Robinson.

https://en.wikipedia.org/wiki/Rube_Goldberg_machine

The present project was inspired by an item on the Arduino Blog:




First I was thinking of using the new RP2040 chip from Raspberry to implement the Hart Clock. But 48 servo motors, and 24 Arduinos seems excessive. So I thought I'd model it using B4X. The result is a digital simulation of 24 analog clocks simulating a digital clock. It is implemented in under 200 lines of cross-platform B4X code.

52axkl.gif





I showed it to my artistic techno-skeptic partner and she liked it! This may also be an engaging teaching example. The project has lots of educational material: use of multidimensional arrays of objects, classes, drawing on canvas, animation, Sleep, and Wait For. All in a compact manageable package.

Here's a picture of kids fascinated by George Rhoads', the Archimedean Excogitation.

Archimedean_Excogitation.jpg
 

Attachments

  • fancyClock.zip
    15.4 KB · Views: 289

josejad

Expert
Licensed User
Longtime User
Maybe you miss the sub "time_change" in the B4A code?

After the first tick I get:

B4X:
Private Sub clockTimer_tick
    CallSub(Me, "time_change")   '<--- This sub doesn't exist
End Sub

B4X:
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
03/27/2021
03/22/2021
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
Error occurred on line: 134 (B4XMainPage)
java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.keywords.Common.CallSubDebug(Common.java:1050)
    at WiL.fancyClock.b4xmainpage._clocktimer_tick(b4xmainpage.java:642)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub time_change was not found.
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
    at anywheresoftware.b4a.debug.Debug.CallSubNew(Debug.java:282)
    ... 17 more
Caused by: java.lang.Exception: Sub time_change was not found.
    at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:326)
    ... 18 more
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
 

William Lancee

Well-Known Member
Licensed User
Longtime User
@José J. Aguilar

I first posted 'NSSClock.zip" which I used for creating the Video for the attached animated .gif - I had commented out a few lines to make the clock transition faster.

The "time_change" Sub is really just an event that I wait for, in order to synchronize all those asynchronous mini clocks.

The "fancyClock.zip" updated in post #1 has the code that transitions every 60000 milliseconds.
 
Last edited:
Top