0

Your shopping cart

0
Subtotal:  0
No products in the cart.
Make your cart full of Floowers 🌷

Use Floower to Breathe Mindfully

Mindful breathing is a very basic yet powerful mindfulness meditation practice. The idea is simply to focus your attention on your breathing—to its natural rhythm and flow and the way it feels on each inhale and exhale. Floower is a beautiful nature-inspired smart device. Using it for meditation and health practices is a perfect fit!

I am going to teach you how easy it is to customize your’s Floower firmware. Start with installing all you need on your computer to be able to communicate with your Floower over USB. Check out the GitHub repository a Quickstart Guide. You have to be familiar with the Arduino framework and C++ programming language.

Ready?

What are we going to code? The mindful breathing meditation goes like this – inhale for 3 seconds then exhale for 5 seconds. And repeat this exercise for 5 minutes. I envisioned the mode to be:

  1. On touch slowly light up and wait 5 seconds to let me get ready for meditation
  2. Slowly open the blossom and increase the light intensity for 3 seconds to let me inhale
  3. Slowly close the blossoming and decrease the light intensity for 5 seconds to let me exhale
  4. Fade after 5 minutes / or when the leaf is touched again
 

This way Floower will mimic my breathing. Expanding and contracting. Very natural and beautiful.

Mindfulness Behavior

Floower software is a state machine. I need to add a class that will change its state based on the leaf touch even or timer event. There is standard behavior – BloomingBehavior. I will be adding my first custom one – MindfulnessBehavior.

First of all, I will create a header file MindfulnessBehavior.h inside the behavior folder with the following content:

				
					#pragma once

#include "behavior/SmartPowerBehavior.h"

class MindfulnessBehavior : public SmartPowerBehavior {
    public:
        MindfulnessBehavior(Config *config, Floower *floower, BluetoothControl *bluetoothControl);
        virtual void loop();

    protected:
        virtual bool onLeafTouch(FloowerTouchEvent event);

    private:
        unsigned long eventTime;
  
};
				
			

What does it do? It defines the new MindfulnessBehavior class that will contain 2 methods and constructors. This class inherits from SmartPowerBehavior class and overrides its 2 methods:

  • loop method is called as often as possible repetitively, allowing you to program the behavior itself.
  • onLeafTouch is called when the leaf is touched. There are 4 types of touch events (touch down, touch up, long touch, and hold touch). This method must return true if the touch was handled successfully.

The next step is to add an implementation of the above-mentioned methods. To do so I will add another file – MindfulnessBehavior.cpp – inside the behavior folder containing the following code snippets:

				
					#include "behavior/MindfulnessBehavior.h"

#define STATE_INHALE 128
#define STATE_EXHALE 129

MindfulnessBehavior::MindfulnessBehavior(Config *config, Floower *floower, BluetoothControl *bluetoothControl) 
        : SmartPowerBehavior(config, floower, bluetoothControl) {
}
				
			

The constructor is pretty straightforward. All I need to do is just pass the parameters to the parent class. The important part here however is a definition of two new states – STATE_INHALE a STATE_EXHALE. State in Floower is represented by a numeric value. When I am adding a custom state I can pick whatever number for my behavior as long as it’s greater than 127. Numbers below 127 are reserved for internal use. These states will represent what your Floower is currently doing.

				
					bool MindfulnessBehavior::onLeafTouch(FloowerTouchEvent event) {
    if (SmartPowerBehavior::onLeafTouch(event)) {
        return true;
    }
    else if (event == TOUCH_DOWN) {
        if (state == STATE_STANDBY) {
            floower->transitionColor(colorPurple.H, colorPurple.S, 0.1, 2000);
            floower->setPetalsOpenLevel(20, 2000);
            eventTime = millis() + 5000;
            changeState(STATE_EXHALE);
        }
        else {
            floower->transitionColorBrightness(0, 5000);
            floower->setPetalsOpenLevel(0, 5000);
            changeState(STATE_STANDBY);
        }
    }
    return false;
}
				
			

When the leaf is touched the meditation mode will either start or stop, remember? In the beginning, it’s wise to call a parent method to handle all system touch events. If nothing is handled I can use the touch for my purposes.

When the state is STATE_STANDBY (Floower is off) I want to set the color of blossom to purple with 10% intensity and 2s transition time. To make the effect even better I will also slightly open the blossom to 20%. At the same time, I will set the even timer to trigger in 5 seconds and change the mode to STATE_EXHALE. The Floower will think it’s in exhale phase and will do the inhale transition on the event timer.

If the Floower is doing something else I want to turn it off to end the meditation mode.

				
					

void MindfulnessBehavior::loop() {
    SmartPowerBehavior::loop();

    unsigned long now = millis();
    if (eventTime <= now) {
        if (state == STATE_INHALE) {
            floower->transitionColorBrightness(1, 3000);
            floower->setPetalsOpenLevel(70, 3000);
            eventTime = now + 3000;
            changeState(STATE_EXHALE);
        }
        else if (state == STATE_EXHALE) {
            floower->transitionColorBrightness(0.1, 5000);
            floower->setPetalsOpenLevel(20, 5000);
            eventTime = now + 5000;
            changeState(STATE_INHALE);
        }
    }
}
				
			

And finally, loop method will take care of the event timer. When the time is up I want to change the Floower’s state.

If the state is STATE_EXHALE it means the exhale phase of the meditation is at the end. So I need to instruct the Floower to show the inhale phase. I will open the petals to 70% and increase the light intensity to 100%. Inhale phase will last for 3 seconds that’s why the timer is set for 3 seconds.

If the state is STATE_INHALE it means the inhale phase just ended. Similarly to above, I will transition the Floower to exhale phase by closing the petals to 20% and decreasing the light intensity to 10% again.

That's almost it

I just finished my first custom Floower behavior. Very exciting. All that left it to use the behavior. I will simply exchange the standard BloomingBehavior and call my MindfullnessBehavior instead. Alter the main.cpp class:

				
					//behavior = new BloomingBehavior(&config, &floower, &bluetoothControl);
behavior = new MindfulnessBehavior(&config, &floower, &bluetoothControl);
				
			

Instead of initializing the BloomingBehavior, I will initialize my MindfulnessBehavior behavior. That’s it! My Floower is now changed into a nature-inspired relaxation device.

That was simple

Now you see that only a few lines of code can customize what your Floower can do. I hope this encouraged you to try to write your own behavior. Feel free to share it with me or create a pull request on GitHub. I would be really happy!

Sdílej článek
Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on email
E-mail

Floower kvete po celém světě

Lidi jako ty už mají Floower doma.