Example for RIC file: Voltmeter

 

Another good example for using the RIC files is a pointer display like it is used by a voltmeter (or amperemeter when you change the description in the scale). For the output of the RIC file you only have to use one single parameter which will be used for the position of the pointer. The scale within the display is designed for using values from 0 to 100 (0% to 100%) – so you have to forward a single parameter with a value from 0 to 100.

 There are only two elements for drawing on the NXT screen – but you need some other elements for a complete output.

Element

Realized by

Parameter

Comment

Background picture for voltmeter

Sprite

 

Contain the picture which will be shown by the next element

Output on Display

CopyBits

 

Display the background image

Transfer function for X value

VarMap

 

Necessary for calculation of the horizontal position of end of line

Transfer functon for Y value

VarMap

 

Necessary for calculating of the vertical position of end of line

Pointer

Line

0 : Wert

Percential value for displaying the pointer

 

When you call the RIC file, than you will see the following picture on the NXT screen:

 

 

The following steps will describe how you can create the RIC file:

 

Step

Description

0

Start the program nxtRICeditV2 and create a niew RIC file.

 

 

1

Insert a new RIC element Sprite which will contain the background image. Press on the following button for adding the RIC element Sprite to the RIC list:

 

 

Afterwards you have to create an image like this:

 

The lines for the scale are not random! They match to the interpolation values of both VarMap elements of the same RIC file!

 

It's importand that the ID of the sprite will be become 1!

 

The position of the image on the available drawing area isn’t important because only the used pixels will be stored in the file. If you make a mistake during creation of the image so you can correct it every time and reduce the used area by pressing the following button:

 

 

 

2

For bringing the image of the Sprite to the NXT screen you need a CopyBits element. Add the RIC element CopyBits to the end of your RIC list by pressing the following button:

 

 

For this example we have to use the complete image of the sprite – so we can adapt the width and height of the source to the size of the image of the sprite. This can be done by a click on following button:

 

 

Afterwards the complete image of the sprite is selected and the destination position is [0,0].

 

 

3

For the next step we need two VarMap elements which can be added to the end of the RIC list by pressing twice the following button:

 

 

The VarMap elements will be used to transfer the given parameter value in the range of 0 to 100 to a X and Y coordinate which stands for the end of the pointer. It’s not necessary to define all 101 possible positions – it’s enough when we define the interpolation points for every position by step of 10. The positions between will be automatically interpolated during the runtime by the NXT.

 

It’s important that the ID of the VarMap elements will be defined with 2 and 3. ID 1 was already used for the ID of the Sprite element. Therefore both VarMap elements should be defined as follow:

VarMap-ID

2

 

VarMap-ID

3

 

Domain

Range

 

Domain

Range

 

0

6

 

0

17

 

10

9

 

10

21

 

20

13

 

20

25

 

30

18

 

30

28

 

40

23

 

40

29

 

50

29

 

50

30

 

60

35

 

60

29

 

70

40

 

70

28

 

80

45

 

80

25

 

90

49

 

90

21

 

100

52

 

100

17

 

Values greater than 100 will be handled like the value 100.

You can speedup the input of all pairs of domain/ranges when you use the clipboard: Mark all 22 values (Domain from 0 to 100 and also the related range values) of the VarMap list and copy it into the clipboard. Afterwards you can update the list of the VarMap element by pressing the following button which can be detected beside the list of domain/range input fields:

 

 

4

The last RIC element will be the Line. This RIC element used constant values (for the beginning of the line) and dynamic values (for the end of the pointer). You need both VarMap elements for defining the position of the end of the line. The RIC element Line will be added to the end of the RIC list by pressing the following button:

 

The attributes for the RIC element Line must be set as follow:

 

Begin of line

End of line

 

X

Y

X

Y

Description

29

3

V[2:0]

V[3:0]

Pointer of the voltmeter

Attention: The end of line has to be use VarMaps – The displaying of V[2:0] means that VarMap 2 will be used together with parameter 0 for calculation of the value during the runtime!

After defining all RIC elements of your Voltmeter you can take a look to your work by pressing the following button:

When you modify the value of Parameter 0 you can detect the change of the pointer of the display. The same result will be given when you call the RIC file within your program. The following NXC code will show how you can use the RIC file within your programs:

 

task main()
{

   int voltmeter[ 1 ];

 

   voltmeter[ 0 ]= 30;    // Pointer should show on value 30

 

   // Draw complete Voltmeter-Display with one call of RIC file!


   GraphicOutEx( 0,0, "Voltmeter.ric" ,voltmeter );


   while( 1 )

      ;
}

 

 

Annotation::

When you would like to have a dynamically RIC file for displaying more than only a Voltmeter, than you have to change three things: Remove the text from the scale, create a new sprite with all possible texts and add a CopyBits element for output of the scale description.

You have to create the image of the sprite like you can see on the left side. Of course you can add some other texts or titles to the shown stack. You only should centre it for optimal position on the background.

 

The Sprite will have the ID 2 – the same ID like the VarMap which will be defined later. But for this case it’s not a problem because the sprite will not need anymore when the CopyBits have displayed the requested text ;-)

 

The gimmick for the title of the pointer display is that we will use the second CopyBits with an additional parameter for addressing the right text. This parameter will be used for defining the vertical start position for the rectangle within the new sprite. The vertical position and the width/height of the copy area is every time the same – also the destination for the output. So you can select the right text by different values of the second parameter. E.g. when this parameter will have the value 6, you can see “0-1V” on the display. When you forward the value 12, than “0-100mA” will be shown.

The additional CopyBits must be defined like this:

Sprite-ID

Pos X

Pos Y

Width

Height

Rel X

Rel Y

 

2

0

P[1]

28

5

15

12

 

Attention: Yellow marked field must be defined as a parameter!

At the end you RIC list should be the same like this:

 

 

 

Here is a short example for using the Voltmeter with dynamic scale text:

 

 
 

#define Scale_0_100_mV     0
#define Scale_0_1_V        6
#define Scale_0_100_mA    12
#define Scale_0_1_A       18
#define Scale_0_100_kOhm  24
#define Scale_0_1MOhm     30

#define Scale_Sound       36

#define Scale_Light       42

 

task main()
{

   int voltmeter[ 2 ];

 

   voltmeter[ 0 ]= 30;           // Pointer should show on value 30

   voltmeter[ 1 ]= Scale_0_1_A;  // Scale is 0 to 1 A

    

   // Draw complete Voltmeter-Display with one call of RIC file!


   GraphicOutEx( 0,0, "Voltmeter2.ric" ,voltmeter );


   while( 1 )

      ;
}

 

 

 

You will find an extended example which used a sound and light sensor in the program  Voltmeter3.nxc