As a demo, we create a special training timer, just to illustrate how such an application can be created in Reactive Blocks. I know: It’s not the usual type of IoT and M2M application! But there is so much we can learn from it:
- How to make an application with a more complex timers that goes through different phases
- How to control use Java SE 8 Embedded with JavaFX from Reactive Blocks
- About the Raspberry Pi as a driver for a screen
- Using the Berryclip extension board
About Interval Training
High-intensitiy interval training is an effective way to train. One timing scheme is called Tabata, after its inventor Izumi Tabata. In this scheme, 20 seconds of intensive work is followed by 10 seconds of rest. This is repeated 8 times for an exercise. Tabata is often done in groups. Eight stations with different exercises are selected for a complete workout. Typical exercises are burpees (yeah, burpees!), push-ups, or kettlebell swings. A participant starts at a station, repeats eight rounds of work, and switches to the next station.
Let’s have a look at the complete system:
The timer runs on a Raspberry Pi, and is connected to a screen via HDMI. The screen shows which phase the training is in (prepare, work, rest, switch stations). It also shows the remaining seconds, and the number of rounds and cycles.
The timer issues also audio commands via HDMI. For instance, it tells when a Tabata cycle is complete and the participants should switch exercises.
The application starts automatically when the Raspberry Pi is powered up. To control the timer, a single switch can be mounted under the screen. For prototyping, we mounted a Berryclip extension board on the Pi. It provides a buzzer, a button and six LEDs.
That’s how it looks like:
With the LEDs we can simulate another function in the application: Some training studios are equipped with some ambient lighting. This gives an additional clue for participants. Red means “work”, green means “rest”, yellow means “prepare”.
The Application in Reactive Blocks
And that’s how the application looks like in Reactive Blocks:
We might have said that before, but… Can you see how nice the entire application is composed from building blocks? That is so nice when you want to quickly know how the system works.
So here’s how everything works together:
At the startup of the application, we wait for the JavaFX screen to come up, and for the speech module to load. Once the speech is loaded, we update the screen.
- The blocks Timed Button, LEDs, Beep and Beeeep provid control over the hardware of the Berryclip.
- Button Logic selects the right action when we click the button, depending on which state the application is in.
- Timer Periodic issues one tick every second. This tick is used by Workout Logic to determine how the LEDs, the screen and the buzzer should be controlled.
The Timer in Action:
Below you can see how the application cycles through the different screens. After we click the button on the Berryclip for the first time, the screen shows Get Ready and counts down. In the work phase, the red LEDs light up, as expected. We can also pause the work phase (grey), and resume. After 20 seconds elapsed, the 10 seconds rest phase starts.
Your Turn: Try it out!
Of course, you can tinker yourself. If you don’t own a Raspberry Pi with a Berryclip, we also included a version that runs on the PC.
Just do the following:
- Sign up for Reactive Blocks
- Install Reactive Blocks
- Import the reference system Tabata Training Timer
- Build the system
Some technical hints:
- Make sure you have Java SE 8 installed on your PC
- Make sure you have Java SE 8 embedded installed on the Raspberry Pi
- Since the application is embedded in a JavaFX container, you need to manually uncomment a code line in the generated code, i.e., after the build process. You find instructions in the class org.reactiveblocks.example.tabatatimer.javafxTabataScreen.java.
- Instead of running the Start.java, you run the JavaFX class org.reactiveblocks.example.tabatatimer.javafxTabataScreen.java, to start the program.