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:
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:
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:
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!
; |
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.
The additional CopyBits must be defined like this:
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_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!
; |
|
You will find an extended example which used a sound and light sensor in the program Voltmeter3.nxc |