7 Segment Display
Segment arrangement for digits 0 to 9
Responding to a sensor
The Seven Segment Display can be used to indicate a value reflecting the state of a sensor connected to Smart Box. The procedure "Sounds" will indicate a sound level on a scale of 0 to 9 in response to a sound sensor connected to one of the Analogue Sensor sockets. This procedure uses the IF...THEN statement to select a sound range and switch on the appropriate number. Note that this procedure presumes that you have created individual procedures to display each number as described previously.
Procedure: Sounds
REPEAT IF SOUND IS GREATER THAN 0 AND SOUND IS LESS THAN 24 THEN zero IF SOUND IS GREATER THAN 25 AND SOUND IS LESS THAN 49 THEN one IF SOUND IS GREATER THAN 50 AND SOUND IS LESS THAN 74 THEN two IF SOUND IS GREATER THAN 75 AND SOUND IS LESS THAN 99 THEN three IF SOUND IS GREATER THAN 100 AND SOUND IS LESS THAN 124 THEN four IF SOUND IS GREATER THAN 125 AND SOUND IS LESS THAN 149 THEN five IF SOUND IS GREATER THAN 150 AND SOUND IS LESS THAN 174 THEN six IF SOUND IS GREATER THAN 175 AND SOUND IS LESS THAN 199 THEN seven IF SOUND IS GREATER THAN 200 AND SOUND IS LESS THAN 224 THEN eight IF SOUND IS GREATER THAN 225 AND SOUND IS LESS THAN 255 THEN nine FOREVER
Using the OUTPUT command
An alternative method of controlling the display is by using the OUTPUT command. This allows you to set all the digital outputs on or off with one command. Each individual output has a value as shown in the following table:
| Output 0 | 1 |
| Output 1 | 2 |
| Output 2 | 4 |
| Output 3 | 8 |
| Output 4 | 16 |
| Output 5 | 32 |
| Output 6 | 64 |
| Output 7 | 128 |
Individual outputs can be switched on by adding up the values in the table and sending this value to Smart Box with the OUTPUT command. The number zero requires outputs 0,1,2,3,4 and 5 to be switched on so by adding up the corresponding values in the table we get the value 63. Try OUTPUT 63 to check that 0 is displayed. Now try OUTPUT 3. The number one will be displayed. Note that the OUTPUT command has also switched off the other digital outputs. In this way the OUTPUT command can be used to reduce the number of program lines that you require. It is of course much more difficult to determine from the program which outputs are going to be switched on when you read an OUTPUT command so this instruction tends to be used by experienced users.