Client Program on LEGO Hub
We provide 3 possible implementations of the program for our Internet Clock to be run on the hub: two are Word Block programs and one is a Python program. Again, you may choose the implementation best for you based on your skill set. If you are to use Word Block to program your client, please make sure you choose the appropriate one based on the version of Spike App you are using.
How the Client Program Works
Within the client program, the Virtual Sensor’s received hour and minute data are always stored in the variables Hours and Minutes, ready to be used any time.
At the beginning, the program will reset the hour and minute hands to zero position to be ready for calibration. For the minute hand, it is directly attached to one of the Spike Prime motors. This minute hand relies on Spike Prime Motor absolute positioning to accurately set its position for the received time. For the hour hand, its driving motor has a 12 teeth gear attached, the gear drives another 30 teeth gear that the hour hand is attached too. Because of the gear ratio, it requires 5 full motor rotations in order for the hour hand to complete a full 12 hour rotation. For this reason, we cannot use absolutely positioning to fix its location, as it may require multiple motor rotations to position the hour hand correctly. Therefore at the beginning of the program, a laser sound is played, the end user must use the left and right button on the hub to set the hour hand’s position to 12 o’clock. Once set, do not touch any key for 5 seconds, and the motor for both the hour hand and minute will be rotated to the correct positions according to the time received. Once this initial position is set, we rely on the fact that the relatively movement require to get to the correct position should be small, and we use the “go shortest path to position” function to get the hour hand iteratively.