Home Up Contents Search

Exercise 3

Solution

A Seven-segment Display

Design and implement a program in MSW Logo that will draw each digit (from 0 to 9) upon call using a seven-segment display format like that used by calculators and digital clocks. This is your most ambitious project yet. Call it Digit.lgo.

Each of the procedures ZERO through to NINE will call other procedures (a through to g) to draw the bars as follows:


Your program will consist of one main procedure called digit which will call upon ten other procedures to draw the digit as follows:

TO DIGIT

  CT CS HT SETSC 0 SETPC 4 SETFC 4
MAKE "KEY first questionbox "Input [Enter a DIGIT (0-9)]
IF :KEY = 0 [ZERO]
IF :KEY = 1 [ONE]
IF :KEY = 2 [TWO]
IF :KEY = 3 [THREE]
IF :KEY = 4 [FOUR]
IF :KEY = 5 [FIVE]
IF :KEY = 6 [SIX]
IF :KEY = 7 [SEVEN]
IF :KEY = 8 [EIGHT]
IF :KEY = 9 [NINE]
; setup the program, screen, etc
; display instructions and wait for keystroke
; run procedure called zero to draw a 0
; run procedure called one to draw a 1
; run procedure called two to draw a 2
; run procedure called three to draw a 3
; run procedure called four to draw a 4
; run procedure called five to draw a 5
; run procedure called six to draw a 6
; run procedure called seven to draw a 7
; run procedure called eight to draw a 8
; run procedure called nine to draw a 9
END



This way all digits from 0 - 9 can be constructed. Good luck!
 
Previous
Send mail to ljschwerin@hotmail.com with questions or comments about this web site.

Copyright © 1999-2002 Leon Schwerin
Last modified: 28 March 2000
1