7 Segment Display: Difference between revisions

From Smart Box
Jump to navigation Jump to search
No edit summary
Line 61: Line 61:
== Segment arrangement for digits 0 to 9 ==
== Segment arrangement for digits 0 to 9 ==


 
<gallery>
File:Output-7-Segment-Display-1.svg
File:Output-7-Segment-Display-2.svg
File:Output-7-Segment-Display-3.svg
File:Output-7-Segment-Display-4.svg
File:Output-7-Segment-Display-5.svg
File:Output-7-Segment-Display-6.svg
File:Output-7-Segment-Display-7.svg
File:Output-7-Segment-Display-8.svg
File:Output-7-Segment-Display-9.svg
File:Output-7-Segment-Display-0.svg
</gallery>


== Responding to a sensor ==
== Responding to a sensor ==

Revision as of 21:10, 20 October 2023

Connecting the display

The Smart Box 7 Segment Display can be used to indicate numeric values between 0 and 9. Each number is displayed by switching on the appropriate group of ‘segments’. The unit is connected to the Digital Outputs on Smart Box. Each Digital Output is connected to the corresponding blue socket on the display. The red socket on the display can be connected to any one of the red Digital Output sockets on Smart Box.

Check the display is working by typing the following Smart Move commands as direct instructions.

Switch on 1,2

Displays the number 1

Switch on 0,3,6

Switches on additional segments to display 3

Getting started

Each of the segments on the 7 Segment Display can be switched on and off individually using the SWITCH ON and SWITCH OFF commands. Usually the Digital Outputs are identified using the numbers printed onto the top of the Smart Box, for example SWITCH ON 1 will switch on Digital Output 1. Each segment of the 7 segment display is labelled on the circuit board using the standard notation for such displays. The segments are labelled a to g and the decimal point is marked dp. The Smart Move software allows the outputs to be renamed to match the display and subsequently makes for easier programming of the unit.

Type the following eight lines in as direct commands to label the outputs as required. Note that there is not a space between the word output and the number.

LABEL OUTPUT0 A
LABEL OUTPUT1 B
LABEL OUTPUT2 C
LABEL OUTPUT3 D
LABEL OUTPUT4 E
LABEL OUTPUTS F
LABEL OUTPUT6 G
LABEL OUTPUT7 DP

Now try switching on one of the segments by typing SWITCH ON C

Creating procedures for each digit

The 7 Segment Display can be used to show the numbers zero to nine. The diagrams below shows the patterns required to display these numbers.

When writing programs for the display you could simply write a line such as SWITCH ON A,C,D,E,F,G but it is not clear from this instruction which character should actually be displayed. This can lead to difficulties when writing a long program particularly if you are not sure that all the segments will be off before you switch the appropriate ones on. The solution to this is to write a procedure for each character.

"zero" shows the procedure to display zero. Create this procedure on your system and test it by typing zero as a direct command. Now create an individual procedure for each character. The diagrams below will help you determine which outputs should be switched on to create each number.

Procedure: zero

SWITCH OFF ALL
SWITCH ON A,B,C,D,E,F

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.