Xem mẫu

130 Note that we`ve specified the value in hexadecimal (-1066) but the display always shows decimal (-4198). pbFORTH provides two words that show or hide individual display segments, basically everything except the numbers: LCD_SHOW (segment -- ) LCD_HIDE (segment -- ) These words show or hide the given display segment. Valid values are shown in Table 6-7. The values that are flagged as a sequence can be repeatedly called to update the display automatically. For example, the datalog indicator (3018) consists of four quarters of a circle. The first time you show 3018, you`ll see one quarter. Show 3018 again, and a second quarter lights up. Do this three more times, and the third quarter lights up, the fourth quarter lights up, and then all the quarters go blank and the sequence begins again. Table 6-7. LCD Segment Numbers Segment Number (Hex) 3006 3007 3008 3009 300A 300B 300C 300D 300E 300F 3010 3011 3012 3013 3014 3015 3016 3018 3019 301A 301B 301C Sequence? no no no no no no no no no no no no no no no no no yes (4) yes (5) yes (5) no no Description Standing figure Walking figure Input 1 selected Input 1 active Input 2 selected Input 2 active Input 3 selected Input 3 active Output A selected Output A backward Output A forward Output B selected Output B backward Output B forward Output C selected Output C backward Output C forward Datalog indicator segments Data transfer segments (ascending) Data transfer segments (descending) Low battery indicator Short range download indicator (table continued on next page) 131 (table continued from previous page) Table 6-7. LCD Segment Numbers (continued) Segment Number (hex) 301D 3020 Sequence? no no Description Long range download indicator All segment (LCD_SHOW only) Conveniently, you can clear the entire display with a single word: LCD_CLEAR ( -- ) This word clears the RCX`s display so that no segments are lit. Input Control Words Before you configure inputs or read values from them, you should initialize pbFORTH`s input system with the following word: SENSOR_INIT ( -- ) This word initializes pbFORTH`s input system. Call it once before working with inputs. Configuring inputs You probably remember that the RCX`s inputs may be powered. The light sensor, for example, is powered from an input. These types of sensors are called active, all others are passive. In pbFORTH, the following words determine whether an input is active or passive: SENSOR_ACTIVE (index -- ) SENSOR_PASSIVE (index -- ) These words set the input described by index to be active (powered) or passive. The index value should be 0, 1, or 2, corresponding to input 1, 2 or 3. You can configure an input for a particular type and mode, just as in NQC: SENSOR_TYPE (type index -- ) This word sets the type of an input, which describes the electrical characteristics of the sensor you. plan to attach. The values for type are shown in Table 6-8. As before, index should be 0, 1, or 2. Table 6-8. Input Type Values Value Description 0 Raw 1 Touch senso 2 Temperature sensor (table continued on next page) 132 (table continued from previous page) Table 6-8. Input Type Values (continued) Value Description 3 Light sensor 4 Rotation sensor SENSOR_MODE (mode index -- ) This word sets the mode of the given input. An input`s mode determines how the sensor values will be interpreted. The modes are shown in Table 6-9. Table 6-9. Input Mode Values Value (hex) 0 20 40 60 80 A0 C0 E0 Description Raw sensor value from 0 to 1023 Boolean, either 1 or 0 Counts transitions from 1 to 0 and vice versa (edge counting) Counts transitions from 1 to 0 (pulse counting) Percent from 0 to 100 Celsius temperature Fahrenheit temperature Shaft angle, 16 counts per full revolution The following example shows how you could configure input 3 for a light sensor: 2 CONSTANT INPUT_3 ok SENSOR_INIT ok INPUT_3 SENSOR_ACTIVE ok 3 INPUT_3 SENSOR_TYPE ok 80 INPUT_3 SENSOR_MODE ok Reading input values Reading input values in pbFORTH is a two-step process. First, you need to tell pbFORTH to go and read the input values: SENSOR_READ (index -- code) This word tells pbFORTH to read the value of the specified input. The actual value can be retrieved with a call to SENSOR_GET, which is described later. A status code is placed on the stack. If code is 0, then the read was successful. Values other than 0 indicate that the RCX was busy and could not read the input value. 133 Having read an input value, you are now ready to retrieve it using one of the following words: SENSOR_VALUE (index--value) This word returns the value of the given input. The range of the returned value is determined by the mode of the input. SENSOR_RAW (index--value) Use this word to obtain the raw value of the input described by index. The raw value will always be in the range from 0 to 1023. SENSOR_BOOL (index--value) This word returns the current value of the given input as a Forth-style boolean. For example, to read the value of the sensor on input 3, you would do this: : read 2 SENSOR_READ 2 SENSOR_VALUE . ; Strictly speaking, of course, you should really check the return code from SENSOR_READ to make sure it was successful. Finally, the current value of an input can be reset with the following word: SENSOR_CLEAR (index--) Some of the input modes count values, like the edge counting, pulse counting, and rotation modes. For these modes, the current count of an input can be reset to 0 using SENSOR_CLEAR. RCX Timers ... - tailieumienphi.vn
nguon tai.lieu . vn