Introduction

Seven Segment Shield is equipped with two 7 LEDs segments and 2 dot LEDs which can easily display two digits. With Smablo seven_segment library you can easily set any digit or dot blink to for example indicating boundary level of something. Seven Segment Shield is working on the 32.768 kHz clock and has 1uA shutdown current which makes it very power efficient.

Applications

Typical application for Seven Segment Smablo Shield is any application that need to display 2 digit values. It can be used for:

  • Displaying temperature for example to use with Smablo Weather Shield
  • Displaying Speed of an object
  • Displaying level of air quality for example to use with Smablo Ari Quality Shield

Getting started

To get started with Smablo Smablo Seven Segment and button shield you will need:

Take Smablo development board from your Smablo Development Kit and place CPU and Smablo Seven Segment Shield on the described connectors like in the pictures and video below: [plugin:youtube]()

{.force-inline} {.force-inline} {.force-inline} When you’ve done connecting Shields you can connect Smablo Development board to your computer with USB cable.

Examples

To show you how to interact with Smablo Seven Segment Shield we ‘ve prepared some demo codes that you can use in your projects. To see how they work open Visual Studio Code and from your Smablo SDK example directory …\libsm\libsm_examples\examples and open one of the following example projects

Independent display

To show you how to interact with Smablo Seven Segment Shield open Visual Studio Code and open seven_segment_independent_display example code just like it was shown on the video below:

[plugin:youtube]()

To run our example code press F5 button to compile and run it like it was shown on the video below:

[plugin:youtube]()

As you can see on Seven Segment Smablo Shield on screen number one the digits increment from 0 to nine and on the other one the digits are decrementing from 9 to zero independently.

[plugin:youtube]()

Number count down

To see the next example open seven_segment_number_count_down example like it was shown on the video below:

[plugin:youtube]()

To run our example code press F5 button to compile and run it like it was shown on the video below:

[plugin:youtube]()

As you can see on the Seven Segment Smablo shield is counting down from 10 and the dot is blinking to indicate that it’s done.

[plugin:youtube]()

Show all numbers

To see the next example open seven_segment_show_all_numbers just like it was shown on the video below:

[plugin:youtube]()

To run our example code press F5 button to compile and run it like it was shown on the video below:

[plugin:youtube]()

As you can see on the 7 Segment Shield all numbers are display from range (0-99).

[plugin:youtube]()

Minimal code

Basic example will show you how to program with Smablo 7 Segment Shield using app_seven_segment library. You should always program your project in this sequence.

#include "app_seven_segment.h"

void example_func(void)
{
    //initialize app_seven_segment
    app_seven_segment_init();

    //configure to display number 1 on the first segment
    app_seven_segment_show_digit(1, APP_SEVEN_SEGMENT_DISPLAY_0);

    //send configuration over TWI
    app_seven_segment_commit_blocking();
}

Basic code example is illustrating you how you should program with Smablo app_seven_segment library.

  1. Include the library just like it was done in the example above with #include "app_seven_segment.h".
  2. Initialize it with app_seven_segment_init() function. Initialization functions need to used only once at the beginning of the program just like it was shown in the example above.
  3. Configure our shield to display what we want. In our example code we’re using app_seven_segment_show_digit() function that will configure 7 Segment Shield to display number 1 on the first segment.

Have in mind that the configuration functions do not send anything to the shield so that no changes will be applied until app_seven_segment_commit_blocking() function is called just like it was shown in code above. Commit functions send the new configuration to the shield over TWI and after its execution all changes will be applied.

How do I?

In this chapter we will show you some common things you can with the 7 Segment Shield

Display single number on display

The example code to display single number on display was shown in Minimal code.

Display 2 digit Number on display

void example_func(void)
{
    //initialize app_seven_segment
    app_seven_segment_init();

    //configure to display number 12 on both segments
    app_seven_segment_show_number(12);

    //send configuration over TWI
    app_seven_segment_commit_blocking();
}

We can display 2 digit number with app_seven_segment_show_number() function. Function takes as parameter an integer number from range (0-99).

Make number blink

#include "app_seven_segment.h"

void example_func(void)
{
//initialize app_seven_segment
app_seven_segment_init();

//Show number 12
app_seven_segment_show_number(12);

//Configure the second digit to blink
app_seven_segment_configure_digit_display_mode(APP_SEVEN_SEGMENT_DISPLAY_MODE_BLINK, APP_SEVEN_SEGMENT_DISPLAY_1);

//send configuration over TWI
app_seven_segment_commit_blocking();
} 

We can make any number blink with app_seven_segment_configure_digit_display_mode() function. Function takes two parameters, the first one is mode of the segment we want to configure and the second one is number of display segment we want to configure. In the example above the mode is set to blinking with APP_SEVEN_SEGMENT_DISPLAY_MODE_BLINK parameter and the configuration will be set to the second segment with APP_SEVEN_SEGMENT_DISPLAY_1.

Turn on dot or make it blink

#include "app_seven_segment.h"

void example_func(void)
{
//initialize app_seven_segment
app_seven_segment_init();

//configure dot on first segment  to blink
app_seven_segment_configure_dot_mode( APP_SEVEN_SEGMENT_DOT_BLINK, APP_SEVEN_SEGMENT_DISPLAY_0);

//turn on the dot on the second segment
app_seven_segment_configure_dot_mode( APP_SEVEN_SEGMENT_DOT_ON, APP_SEVEN_SEGMENT_DISPLAY_1);

//send configuration over TWI
app_seven_segment_commit_blocking();
} 

Seven segment Smablo Shield also have 2 LED dots that you can use in your projects, you can simply turn them on or make them blink with app_seven_segment_configure_dot_mode() function. In above example we’ve shown the both cases.

The app_seven_segment_configure_dot_mode() takes two parameters the first one is mode we want to configure. First function will make first display segment with APP_SEVEN_SEGMENT_DISPLAY_0 to blink with APP_SEVEN_SEGMENT_DOT_BLINK.

The second app_seven_segment_configure_dot_mode() function will simply turn on the dot on with APP_SEVEN_SEGMENT_DOT_ON the second segment with APP_SEVEN_SEGMENT_DISPLAY_1 parameter.

app_seven_segment library reference

To make your work with Smablo products easier and faster we prepared app_seven_segment library for use with 7 Segment Shield. All of available functions and their descriptions can be found in app_seven_segment.h.

The functions in this library can be divided into 3 groups and to always expect proper work of the Smablo 7 Segment Shield you should use them in this sequence:

  • Initialization functions like app_seven_segment_init() that should be used once at the beginning of your program,
  • Configuration functions like app_seven_segment_show_digit() or app_seven_segment_configure_dot_mode() that will configure our shield, but remember it’s all they do, configure functions won’t change anything until we will use the next type of functions.
  • Commit functions like app_seven_segment_commit_blocking() those functions will send all of the configurations made to shield. Only after executing this type of function you will see the change of behaviour of the Top LED and Buttons Shield.

So your code should look similar to the below snippet:

#include "app_seven_segment.h"

void example_func(void)
{
    //initialize app_seven_segment
    app_seven_segment_init();

    //configure to display number 12 on both segments
    app_seven_segment_show_number(12);

    //send configuration over TWI
    app_seven_segment_commit_blocking();
}

The enumeration types and structures that will be required by the functions are located on the top of the library file, we will often come back to them to change the parameters of the on shield features.

app_seven_segment_init

Prototype:

void app_seven_segment_init(void)

Function is used to initialize the shield. We only need to use it one at the beginning of our program like in code snipped above.

app_seven_segment_show_digit

Prototype:

void app_seven_segment_show_digit(const uint8_t digit, const app_seven_segment_display_t display_no)

Function is used for configuration of the digit we want to show on the one of the segments. Function takes 2 parameters:

  • digit we want to show from range (0-9) integer value
  • display_no type of app_seven_segment_display_t which is the segment number that we want to display our digit

Thus the correct use will this function will look like below:

#include "app_seven_segment.h"

void example_func(void)
{
    //initialize app_seven_segment
    app_seven_segment_init();

    //configure to display number 1 on the first segment
    app_seven_segment_show_digit(1, APP_SEVEN_SEGMENT_DISPLAY_0);

    //send configuration over TWI
    app_seven_segment_commit_blocking();
}

The example above will display number 1 on the first segment.

app_seven_segment_show_number

Prototype:

void app_seven_segment_show_number(const uint8_t number)

Function is used for configuration of the number we want display on both segments. Function takes one parameter, integer value from range (0-99) Thus the correct use will this function will look like below:

#include "app_seven_segment.h"

void example_func(void)
{
    //initialize app_seven_segment
    app_seven_segment_init();

    //configure to display number 12 on both segments
    app_seven_segment_show_number(12);

    //send configuration over TWI
    app_seven_segment_commit_blocking();
}

The example above will display number 12 on both segments.

app_seven_segment_configure_dot_mode

Prototype:

void app_seven_segment_configure_dot_mode(const app_seven_segment_dot_mode_t dot_mode, const app_seven_segment_display_t display_no)

Function is used for configurating the dot LED placed on both segments. Function takes 2 parameters:

  • dot_mode type app_seven_segment_dot_mode_t which determine the mode of the dot. We can made the dot blink with APP_SEVEN_SEGMENT_DOT_BLINK, turn on with APP_SEVEN_SEGMENT_DOT_ON and off with APP_SEVEN_SEGMENT_DOT_OFF.
  • display_no type app_seven_segment_display_t which determine the display segment we want to display the number on. We can choose between APP_SEVEN_SEGMENT_DISPLAY_0 and APP_SEVEN_SEGMENT_DISPLAY_1

Thus the correct use will this function will look like below:

#include "app_seven_segment.h"

void example_func(void)
{
//initialize app_seven_segment
app_seven_segment_init();

//configure dot on first segment  to blink
app_seven_segment_configure_dot_mode( APP_SEVEN_SEGMENT_DOT_BLINK, APP_SEVEN_SEGMENT_DISPLAY_0);

//send configuration over TWI
app_seven_segment_commit_blocking();
} 

The example above will make the dot LED blink with use of app_seven_segment_configure_dot_mode() on the first segment.

app_seven_segment_configure_digit_display_mode

Prototype:

void app_seven_segment_configure_digit_display_mode(const app_seven_segment_display_mode_t display_mode, const app_seven_segment_display_t display_no)

Function is used to configure the display mode of the digits for selected display. Function takes 2 parameters:

  • display_mode type app_seven_segment_display_mode_t which determines the behavior of the digit. We can display digit normally with APP_SEVEN_SEGMENT_DISPLAY_MODE_NORMAL or make it blink with APP_SEVEN_SEGMENT_DISPLAY_MODE_BLINK
  • display_no type app_seven_segment_display_t that select the display segment we want to configure the mode of the number on. We can choose between APP_SEVEN_SEGMENT_DISPLAY_0 and APP_SEVEN_SEGMENT_DISPLAY_1 Thus the correct use will this function will look like below :
#include "app_seven_segment.h"

void example_func(void)
{
//initialize app_seven_segment
app_seven_segment_init();

//Show number 12
app_seven_segment_show_number(12);

//Configure the second digit to blink
app_seven_segment_configure_digit_display_mode(APP_SEVEN_SEGMENT_DISPLAY_MODE_BLINK, APP_SEVEN_SEGMENT_DISPLAY_1);

//send configuration over TWI
app_seven_segment_commit_blocking();
} 

Example code above will display number 12 on the both of the segments and will configure the digit on the second segment to blink with app_seven_segment_configure_digit_display_mode()

app_seven_segment_commit_blocking

Prototype:

void app_seven_segment_commit_blocking(void)

Function is used for sending the configuration to the shield. After calling this functions the changes will be applied to the shield.

Advanced