A new way to design embedded app' using Luos [Step 4]


Intro: The purpose of this tutorial
Step 1: Make a basic alarm
Step 2: Make our alarm adaptable and hot-pluggable
Step 3: Add another app controlling the alarm
Step 4: Make our alarm evolve using a truck horn and more
Step 5: Connect our system to the cloud

Make our alarm evolve using a truck horn and more

For now our alarm doesn’t make any noise, which is sad for an alarm. Let’s make some noise.

To do that, I will add another board to my setup with a power switch.
In this power switch, I put a 12V truck horn producing 150db.


To control it I will simply have to manage it on my apps and use the standard power_switch driver.

Add truck horn on alarm_controller app

I simply want the horn to turn on at the same time the red LED is blinking. So I add a small message generation after the LED’s one in the loop of the app :

id = id_from_alias("horn");
if (id > 0)
{
    // we define a horn
    uint8_t horn = 0;
    if (!blink)
    {
        // turn the horn on
        horn = 1;
    }
    msg_t msg;
    msg.header.target = id;
    msg.header.target_mode = IDACK;
    msg.header.size = sizeof(uint8_t);
    msg.header.cmd = IO_STATE;
    msg.data[0] = horn;
    luos_send(app, &msg);
}

As you can see, I call the power_switch driver “horn”. When you use alias to get ID of a module, always make sure to rename it.

NOTE : The simplest way to rename a module is to use a gate and Pyluos.

Add truck horn on start_controller app

In this app, I add a small “BIP” when locking or unlocking the bike. In order to add it, I have to add more code than in the previous app to manage time properly.
I let you consult the final code here.
I took advantage of this code modification to add some fancy animation on the LED, allowing it to be used as bicycle headlight.

Improvement clue

To make it usable in real life, we should probably select something less noisy than a truck horn which is really painful for the ears.
Also we should add a real locking system able to lock the bike wheel using a motor and a mechanism like this one:


We can also add connectivity to set up the bike using a mobile app or something. This part is interesting, so let’s talk about that on the next chapter.

If you have any question or comment about this step of the tutorial, feel free to reply to this post.

<< Previous (Step 3: Add another app controlling the alarm) | Next (Step 5: Connect our system to the cloud) >>