1.

0 Authors Self-Assessment
The engineering contribution that this project creates is twofold. The project uses a brand new rapid-prototyping technique to create the first handheld LOGO programming devices. The project also resulted in the creation of a new design of device drivers that if published, could be of great use to other users of this microcontroller. The contribution of this project is relevant to engineering as it combined a blend of both electronic and software engineering that uses new techniques and hardware to solve a series of complex problems. A graphical system on a chip with relatively limited resources involved a large amount of resource management and compromises that are common in any engineering problem. The software drivers were deliberately written to be clear and understandable to allow other users of the microcontroller to use the code for this project in other projects without having to rewrite an entire control library. The LCD driver in particular is complex and I have already been able to help others through my experience. The LOGO engine is designed to be as flexible as possible so that the command base can be expanded and other hardware can be attached to the device. An engineer at arm has already asked if the device could be used as the engine for a computerised etch-a-sketch. This project should be considered an achievement as a fully working first of its kind device, has been designed, implemented and programmed making use of limited resources and funding to create a system that could be used to teach

children with little technological experience about the basics of modern computer science. The projects main weakness lies in the range of commands currently available to the system. Due to the development time scale and input device used, the range of input commands is limited to a basic set of LOGO functions. With more time however, this range of functions could be easily increased as it would require only a simple change to the interpreter functions.

2

2.0 Summary
The aim of this project was to design, implement and program a hand held programming language teaching device. This report covers each stage of the development process and describes in detail the thought process and methods used to solve the various problems encountered. The main ‘brain’ of the project was the mbed microcontroller provided by ARM Holdings which is a NXP LPC1768 Cortex-M3 based microcontroller with a number of useful component interfaces. The LOGO programming language was chosen as the language to be taught by the device and as it is particularly graphical, a mobile LCD display from a Nokia 6100 was used. In order to input command and navigate about the user interface, a 4x4 matrix keypad was used and allowed the input of commands, command operands and navigation commands using a limited number of keys. The device is also able to produce sound using a magnetic midrange speaker. A 9V battery drives the device but it can also be powered by a USB connection to a PC. This project was mainly software based, and the hardware drives and user interface were written using C++ and the mbed standard libraries. The LCD driver allows the drawing of shapes, colours and text to the display and the speaker allows the output of a MIDI specification note for a given duration. The user interface consists of two different modes, a task mode and a free mode. The task mode allows a teacher to set an exercise that the student completes and the free mode allows students to experiment with their own designs.

3

hand held learning device was created using a rapid prototyping technique with a new microcontroller to teach children about the basics of programming.This report shows that an easy to use. 4 .

A reasonable number of LOGO commands must be included to allow students to experience a range of programming techniques. 3. 5. 5 . The battery life of the device must be of a reasonable length as access to new batteries may be limited. Considering the target end users. This project will be deemed a success if all of the above objectives are achieved.0 Introduction The aim of this project is to use the mbed microcontroller provided by ARM holdings to design and program a device that is able to teach the basics of the LOGO programming language. The device must be robust and portable in order to be supplied to children to take home for completing homework assignments. 4. The device must allow teachers to upload tasks to the device for the students to complete and practice and be able to download results after a task has been completed. 2. The development and potential manufacturing cost of the device must be kept to a reasonably low level. 1. a number of requirements must be adhered to for the project to be deemed a success.5. The target users of the device are young children in third world countries that do not have access to modern computing technologies.

The author describes FORWARD. A number of variations between different forms of LOGO are discussed. it was the decided that the area which required the most preliminary research is the background and potential of the LOGO programming language. BACKWARD. He seems to put great emphasis on the usefulness of producing mathematical concepts such as triangles and other shapes that are sometimes difficult to grasp. This will help in the development of the device specification as it will identify the key areas of the LOGO language that other academics fell gives it a value in education. words and procedures. but in general. This suggests that the graphical and angular LOGO commands may be an important factor in the educational value of the language.0 Literature Review As the hardware base for this project has been dictated by the engineers at ARM Holdings. 6 .Peter Rossi This publication focuses on three main types of LOGO commands.6. Logo programming . LOGO logic commands are discussed and the REPEAT command is deemed the most important as it reduces command repetition and introduces students to logical program statement. Commands are referred to as procedures. The author has a strong opinion that these three main features allow children to develop skills that are ‘useful in other worlds but computing’. turtle graphics. LEFT and RIGHT as the fundamental LOGO drawing commands. the fundamental LOGO commands are uniform across most versions.

These must also be considered when drawing up the system specification. On the whole the author expresses the need for a number of elements in order to make the teaching of LOGO a success. 7 . This is a particular interesting idea as children in developing countries may not have access to musical instruments. Again the REPEAT command and drawing commands with angular themes are described as the most beneficial experiences.Katrina Blytheii This publication provides a more up to date view of the LOGO language as it was published seven years later than ‘LOGO Programming’. Children learning with Logo . there are a number of features that have been invented more recently and they will need to be considered along with Mr Ross’s suggestions. the draw commands were only able to draw in black and there were no colour options. The author also emphasises the benefits of control technology and turtle graphics. One of the most impressive new features of the LOGO language is the ability to produce 3D looking shapes. The user only had the choice of black or background colour (erase).When this book was written. Text abilities are discussed in some depth as are variables. The author makes an interesting point about way in which computer programs often rely on a student sharing and discussing ideas to try and find a workable solution. and this helps to develop social skills. Another interesting set of functionality described is the use of the language to produce music. however due to the age of this publication. This meant that a number of features that were not present in that book are now discussed.

Children learning LOGO programming. The idea is that the pupils use the device to experiment with different shapes and angles to try and see if the results match their expectation. The report focuses mainly on the use of LOGO to teach trigonometric principles and encourage trial and error learning. Each of these publications has a slightly different take on the use of the LOGO programming language in education and they have helped to point out the key language features that are beneficial to the users. The recursion features are also important and the REPEAT command especially is also a key learning tool. It once again reiterates the usefulness of the drawing commands and the use of recursive commands such as REPEAT.Many useful concepts are discussed in this book but it omits any reference to RGB colour which I had hoped would be discussed as it had existed for a good number of years before this publication. Drawing commands seem to be very important due to their ability to illustrate different concepts and encourage creativity and these features are a must. The development of sequential thinking is also discussed in detail and the benefits or recursive commands and sub-functions are highlighted. This again reinforces the basic LOGO drawing function. This report is particularly useful as it gives an insight to the areas of the LOGO language which are useful to students and those areas that are not. The inclusion of sound the project is also an interesting idea as children in developing countries may not be able to get access to musical instruments and composing could be a completely new experience for them. Although it was only 8 .Richard Nossiii The purpose of this report was to investigate the use of the LOGO programming language in primary education.

9 . but the only one that is difficult to create without a specific command is the arc or circle. Triangle. squares and other shapes can be created with the basic drawing commands but the circle command could be included on its own. colour is an important aspect of modern LOGO and can really enhance the creations the users can produce. Other basic commands that are required are cursor movement commands and display refresh commands. A number of basic shapes were included in the language specification.touched on in the researched publications.

The LOGO language was chosen over other languages as it consists of pseudocode commands that are easily understandable without even a basic knowledge of programming.1 Commands It was decided that the command scope of this device needed to fairly limited but should contain the fundamental commands to teach basic function usage and logic structures. The number of on screen pixels that a unit corresponds to is determined by the systems ‘scale’ parameter. There are roughly 221iv commands in the LOGO language but this number varies based on the software implementation. FORWARD -Moves the turtle forward a certain number of units. From the list of LOGO commands the following will be included in the first revision of the device: 1. The system must also be programmed so that the interpreter module will have the potential to be expanded in the future. Commands such as ‘FORWARD’ and ‘LEFT TURN’ are easy to understand and the language is already accepted as a good method of introducing young children to the world of programmingv. It is an adaptation of the LISP programming language and is mainly used for functional programming.0 Software Specification The language chosen for this device was the LOGO programming language. 7. 10 .7. The language was originally created for educational use and was used to demonstrate the underlying concepts of computer science.

11 . Figure 3: Right Turn Command 4. taking into account the current angle of the turtle.Figure 1: Forward Command 2. BACKWARD -Moves the turtle backwards a certain number of units. RIGHT TURN -Rotates the turtle a specified number of degrees to the right. Figure 2: Backward Command 3. taking into account the current angle of the turtle. LEFT TURN -Rotates the turtle a specified number of degrees to the left.

Figure 4: Left Turn Command

5. PENSTATE -Tells the device if it should or should not leave a ‘trail’ when the turtle is moved about the screen. When this command is issued, the current pen state is inverted.

Figure 5: Penstate Command

6. SETX -Sets the current horizontal position of the device. 7. SETY -Sets the current vertical position of the device. 8. SCALE -Sets the devices scaling variable. This variable determines the number of screen pixels that a unit distance in the drawing functions corresponds to.

12

Figure 6: Scale Command

9. BEEP -Produces a sound of a specified note on the MIDI scale (from 0 to 127) for a given duration. 10. CLEAR –Clears all drawings on the screen and sets the drawing parameters (pen colour, turtle position, background colour) to their default values. 11. SETBG -Sets the background colour of the canvas to a specific colour based on the input of RGB values. 12. CIRCLE -Draws a circle of specified radius with the centre point at the current location of the turtle. The number of pixels of the radius is determined by the current ‘scale’ variable of the device.

13

Figure 7: Circle Command

13. REPEAT -Allows a list of commands to be entered between this command and the ENDREPEAT command and this list will be repeated a user specified number of times. 14. ENDREPEAT -Terminates the list of commands initiated using the REPEAT command. 15. SETPC -Sets the colour of the objects and lines drawn on screen. The colour is set to a specific colour based on the input of RGB values. These commands correspond to functions within the device and these allow the user to produce visual and audible results for their entered commands. The system is to be programmed so that it is relatively easy to add commands to the system at a later date.

14

The user is given the choice of mode when the device starts and they are able to change the mode simply by pressing the reset button. ‘Free’ mode and ‘Task’ mode. It was also decided that it would be useful for students to be able to practice on the device and generate their own creations as well as performing the specified exercise. can be changed easily) and the system will process and output the result. the device will operate in two different mode. Figure 8: Operational Modes Example The ‘Free’ mode allows the user to enter up to fifty commands (limit imposed to reserve system memory.2 Modes of Operation From the specification. 15 . For this. it is required that a teacher must be able to upload a task to the device for the student to complete.7.

and then requires the user to enter commands for each task on a given worksheet. Figure 10: Task Mode Example 16 . The marked work is then saved to the device for the teacher to download when the device is returned.Figure 9: Free Mode Example The ‘Task’ mode is more complex than the ‘Free’ mode as it loads a set of predefined instructions from memory. These entered commands are then be compared to the loaded exercise and the work is displayed and marked by the device.

however the code for the chosen peripherals needed to be written from scratch.7. The command interpreter is a function that will convert the commands entered into the system into outputs. The mbed has a C++ library that helps with interfacing between numbers of different hardware components.3 Key Software Modules There are four key modules that allow this system to function. Figure 11: Software Modules Organisation The device drivers allow the user to interface with the system and for results to be displayed. This module is subject modification as new commands are added in the future. and then performs a number of system functions to produce the desired output. numbers and system navigation commands from the users input 17 . The system also required a large amount of code that relates directly to specific LOGO commands such as ‘FORWARD’ and ‘BACKWARD’. The input handler module is used to handle the process of receiving LOGO commands. This module is supplied with a command and its operands. The complexity of these drivers depends upon the method of communication with the end user.

and it was important to replicate this functionality in the device. The screen chosen was from a mobile phone. it was decided that the best solution was to use a LCD screen. This is the key component in loading and saving data from the exercise file and user input respectively. as that would allow the system to draw good quality colours and shapes and maximise the visual experience for the end users. The screen also needed to 18 . The turtle represents the virtual tip of a pen and any movements of the turtle will result in a visual change of any pixels that turtle passes through on route to its specified destination. 8. With all of these requirements considered.device. This visual method of displaying results means that the chosen method output from the device needed to be able to handle text. The disk access functions module handles the process of transferring commands and operands from volatile device memory to non-volatile disk memory. 8. This module also handles the transfer of entered commands into the system memory and verification of the entered operands.0 Hardware Design A key step in the creation of this device was to specify the peripheral hardware components and the methods by these components handle data input and output.1 Component Specification The LOGO programming language is a real-time command centric language and a majority of its functions result in the manipulation of a graphical ‘turtle’. graphics and precise pixel definition. The original LOGO language also allows for definition of pixel colour.

numbers for command operands and navigate all with the same button. In the software specification. This keypad is a good compromise between functionality and size and provides the end user with an easy to use method of interfacing with the device. It was also important to consider an input method that would be compact enough to fit into a hand held device. power consumption and colour definition to make it a feasible solution for the devices main interface. The sixteen keys allow for the input of each required command by pressing a specific key and also allow for a return key. The main aim of the device is to teach a basic level of programming ability. it was stated that the device would require a numerical input range from zero to nine and the possibility to enter fifteen unique commands. Based on these requirements a 4x4 button keypad was chosen for entering data into the system. The ‘LEFT TURN’ and ‘RIGHT TURN’ commands will also be used to make decisions within the user interface in the form ‘<-YES NO->’. and for this reason the input to the system should not be too complex as this may be daunting for users with little technological experience. By using different stages for the input. It would be possible to use other forms of LCD screen for this task but the mobile screen has the correct balance of size.draw a minimal amount of power from the microcontroller and also be of a reasonable colour definition (nothing less than 256 colours). the user can use these sixteen buttons to enter commands. which can signify the end of a command input or to navigation around the user interface. 19 .

the device is open to a wider age range. and for this purpose a magnetic driven speaker from a desktop computer is included. By simplifying the interface through the use of predefined commands. 20 . This speaker allows the system to produce a good range of musical notes for the end user to experiment with.Figure 12: Navigation Decision Example The possibility of using a full keyboard for input of commands was considered but deemed an unachievable option due to the required small form factor of the device and the desired simplicity of the interface. as students will be able to learn basic programming techniques from the device without having to have a complex understanding of the written language structures involved. It was also decided to include the functionality to be able to produce sound from the device.

The controller also has a number of interfaces that are well suited for use with the chosen peripherals. The mbed is based on a Cortex-M3 core running at 100MHz with 64KB of RAM.vii The LPC1768 is one of the industry’s first Cortex-M3 processors that had a clock speed of 100MHz and this will provide more than enough processing power to enable the device to provide a graphical and real time user experience. viii 21 .8.2 The mbed Microcontroller vi Figure 13: MBED Microcontroller Pin Out The main component of the project is the mbed NSP LPC1768 microcontroller and this is the device that will be programmed at meet the specification defined in the previous section.

14).2.1 to 8.org/compiler and compiled remotely (fig. 22 . code is written on an online IDE located at http://mbed. Digital I/O & Bus I/0 SPI interface PWM interface Local File System access These interfaces are described in detail in sub-sections 8. This microcontroller has a number of functions and interfaces that make it ideally suited for the rapid prototyping of devices. This allows access to the development environment from any machine on almost any platform that has Internet access. especially devices of this projects nature.2.4 In order to program the mbed. The compiler allows the inclusion of pre-defined libraries from the mbed community.The mbed has 512KB of zero-wait state on chip flash memory that give sufficient space for storing exercise data and result. The microcontroller is programmed using the C++ language and will be the primary language other than LOGO that is use in this project. This library simplifies interfacing with the mbed’s ports and internal components by creating structures and classes that can be accessed from the main body of the program. but the only library that I will be including is the ‘mbed’ system library.

either via the USB connection to a PC or with 4.0V applied to the VIN pin of the PCB. Both method of powering the board generate a 3. The mbed can be powered in two ways.3V regulated output on the VOUT pin and this is used to power the peripherals. 5. When the mbed is reset the device will locate the most recent binary file in the flash memory and copy that binary file to the devices programmable memory. but when prototyped will use a 9V battery. and can then be flashed to the chip by placing the binary on the device’s internal flash memory.bin (binary) file. The device is powered through the 5V USB supply while undergoing testing as the USB connection is used for the transfer of binary files. 23 .0V is available on the VU pin. If powered by USB. but only with this supply method.Figure 14: Online Compiler Displayix The compiled code is downloaded from the Internet as a . This is done by connecting a USB cable to the device and using it as a solid-state removable disk drive.5V-9.

The input can then be read by simply reading of the variable of input component and the output can be set by simply setting the output component equal to one or zero. These output pins are sufficient to drive the peripherals connected to the system.2.2 SPI Serial Specification The mbed has two sets of Serial Peripheral Interface pins that it can use to interface with devices.1 Digital I/O Specification The mbed has a total 27 pins that can be used for digital input and output. and voltages greater than 2. For output.2. The SPI port has a configurable format and clock frequency and this is important for the correct interfacing between the microcontroller and the LCD screenxi. This interface is especially important for interfacing between the 4x4 matrix keypad and the microcontroller. The digital pins are by default connected to internal pull-down resistors where input voltages less than 0.3V at logic one. Each pin can source or sink a maximum of 40mA with a total of 400mA across all pins. each pin is 0V at logic zero and 3.8V are regarded as logic zero. The SPI master pin 24 .0V are regarded as logic onex. 8.8. The digital input/output interfaces allows buttons and LEDs to connect to the system. and this is necessary for displaying operational status and accepting inputs. A digital pin is defined in the compiler using ‘DigitalIn component(pX)’ for input and ‘DigitalOut component(pX)’ for output where ‘component ‘ is the name of the object instance and ‘X’ is the number of the digital pin that is in usevii. The interface can be used to write data word out of the SPI port and return the data received back from the SPI slave.

‘x is the number of bits per SPI frame (4-16) and ‘y’ is the clock polarity and phase mode (0-3). The format of the SPI can be set using the ‘device. A SPI port is defined in the compiler using the code ‘SPI device(mosi. Finally data can be written and returned from the port using the code ‘int x=device. master output slave input (MOSI) and master input slave output (MISO) and does not have a slave select (SS) pin as the chip only supports communication with one slave per port.sclk)’ where ‘device’ is the name of the SPI port and ‘mosi’.3 Pulse Width Modulation Specification The mbed PWM port allows control of the frequency and mark-space ratio of a digital pulse train. 8. This will not be a problem for applications as the system requires only a single slave on that port to communicate with the display.format(x.frequency(x)’ where ‘device’ is an instance of a SPI port object and ‘x’ is the frequency of the clock in Hz (default value is 1MHz). but mbed SPI port uses only a clock (SCK). This is especially important for the implementation of the systems speaker.2.write(y)’ where ‘x’ is the variable that will store the value returned from the slave and ‘y’ is the date to be written to the slave by the master. ‘miso’ and ‘sclk’ refer to the pins that each of the namesake pins are connected to. The frequency of the port can be set using the code ‘device. The slave then returns a bit stream that is also synchronised to the clock signal.miso.y)’ code where ‘device refers to a SPI port defined earlier. The power of the signal is determined by 25 . The PWM port generates a square wave that oscillates on and off with a given period for each statexiii. A conventional SPI port has four pinsxii.generates a clock to synchronously drive a bit stream in a serial format slave.

8.4 Local File System The ‘Local File System’ refers to the mbed’s solid-state flash memory and this component is used extensively throughout this device. and will be output from the system in order for the teacher to be able view a pupils attempt and mark. The ability to produce an oscillating signal of a specified period allows the system to generate the particular tones required for the speaker output and this will be discussed in subsequent sections of this report.period(float period)' command where the period is a value in seconds. The mbed library already has a class dedicated to simple PWM interactions. The duty cycle of the signal is defined using the ‘instanceName. 26 . The local file system is a class located within the mbed code library that implements the common file access functions of the C++ fstreamxiv library including reading and writing of binary data. The period of the signal is set in the compiler using the ‘instanceName.2.0. Data is stored on disk in the form of text files that are read into the system enabling a teacher to set an exercise. A connection the mbed’s local file system is made using the code ‘LocalFileSystemlocal(“local”)’xv and this object can then be used along with the C++ file access functions to write and read data from a specified file. and an instance of this class is declared using the code ‘PwmOut instanceName(pin)’ where ‘instanceName’ is the name of the object been created and pin is the pin number that the output device is connected to.write(float duty)’ command where the duty cycle is expressed as a percentage in the range 0.its duty cycle and this is expressed as a percentage of on time to off time.0 to 1.

This means that if the column of the button is high at that particular point in time. When a button on the matrix keypad is press edit creates a connection between the column and row of that particular button. ROW 1 ROW 2 ROW 3 ROW 4 COL 1 COL 2 COL 3 COL 4 Figure 15: Matrix Keypad Arrangement The matrix arrangement means that eight connecting wires are required to connect each row and column of the keypad to the microcontroller.3 Matrix Keypad The keypad has four rows and four columns that are connected in a matrix arrangement as shown in figure 15. the row will also be driven high. The pins dedicated to the keypad are given in table 1.8. and by connecting the keypad rows to digital input pins. 27 . the keypad will be able to send provide the microcontroller with the row and column of the pressed button giving a unique input. An input is obtained from the keypad by driving each individual column of the device high.3v). Thus by connecting the columns of the keypad to digital output pins that can be driven high and low in sequence. setting that particular columns value to logic one (3.

Element Row 1 (IN) Row 2 (IN) Row 3 (IN) Row 4 (IN) Column 1 (OUT) Column 2 (OUT) Column 3 (OUT) Column 4 (OUT)

Pin P24 P23 P22 P21 P28 P27 P26 P25

Table 1: Marix Keypad Pin Assignements

The keypad is arranged in the layout show in figure 16.

1 4 7 A

2 5 8 0

3 6 9 B

F E D C

Figure 16: Keypad Layout

As the keypad will be used to enter commands and numbers, the keys will be relabelled with the text shown in figure 17.

28

SCALE 1 SETPC 4 PENSTATE 7

BEEP 2 SETBG 5 CIRCLE 8

CLEAR 3 SETX 6 SETY 9

REPEAT

ENDREPEAT

0

Figure 17: Modified Keypad Layout

In order to drive the columns high sequentially, an input signal of one must be applied to each column individually. The microcontroller outputs a four-bit signal where each bit corresponds to an individual column control line. The sequence should take the form ‘0001 0010 0100 1000’ where the most significant bit refers to column one and the least significant bit refers to column four. The bit with the value of one is shifted left by one place during each iteration. Each time a column is driven high, the microcontroller will test the rows for an input to see if a button has been pressed. The rows will be all logic zero by default due to the internal pull-down resistors so when one of the pins is read as high, the microcontroller will know that a button has been pressed. From a combination of row and column information, the device software returns a unique hexadecimal value that corresponds to a specific button that can then be processed. The method of converting these returned rows into key values will be explored in the software design section of this report.

29

8.4 LCD Display
The display that will be used is an imitation Nokia 6100 colour LCD display. It has a resolution of 132x132 pixels and full 4,096 colour pallet which makes it a good match for a graphically orientated interfacexiii. A 9-bit serial interface is used to communicate with the display and is connected to one of the SPI ports on the microcontroller.

xvi

Figure 18: LCD Display Dimensions

The LCD logic requires 3.3V at 2.5mA to work and the LCD backlight requires 45mA at 3-9V. xviiThe logic can be driven simply by the 3.3V regulated output from the mbed VOUT pin and this signal can also be converted by the displays on-chip voltage regulator to supply the back-light. When the 3.3V pin supplies the backlight, the voltage regulator will draw 324mA from the microcontroller. When the device is powered through USB, the backlight benefits from been driven from an external battery as the current drawn in this situation is close to the USB 500mA limit.

30

The screen is installed on a breakout board from Sparkfun Electronics allowing it to connect directly into a breadboard for testing.3V) NOT CONNECTED GND LED GND (For Back Light) LED V+ (6-7V) (For Back Light) Table 2: LCD Pin Assignments On the breakout board.3V) RESET SDATA SCK CS VCC-DISPLAY (3.3V-7V) Table 3: LCD Breakout Board Pin Assignment 31 . pins eight and nine are connected with a soldered bridge.3V) Backlight Driver Input (3. The pin out for the LCD cable is given in table 2. Mbed Pin P15 P16 P8 P7 P5 P9 P18 P19 P20 GND Vo Vu Pin 1 2 3 4 5 6 7 8 9 10 11 12 Function Push Button 1 (Active Low) Push Button 2 (Active Low) CS (Chip Select) SCK (Serial Clock) DIO (Serial Data Input/Output) Reset Green LED (Active Low) Blue LED (Active Low) Red LED (Active Low) GND Logic Supply (3. This board also includes two push buttons and a tricolour LED is incorporated into other device functions. Each of the remaining pins is soldered to the PCB of the breakout board and the pin out of this board is given in table 3. Pin 1 2 3 4 5 6 7 8 9 10 Function VCC-Digital (3.

eight and nine are connected to digital out pins for the tri-colour LEDS and pins one and two are connected to digital-in pins for push button input. The blue signifies that the system is currently busy and in most situations is accessing the internal flash storage. The green LED signifies that the system is active and awaiting user input.xviii 32 . The red LED signifies an error has occurred or that the system has completed all tasks.The tri colour LEDs are active low on this chip and as the default microcontroller digital I/O is active low the outputs are initially driven high to turn the LEDs off. The display requires a reset and chip select signal so pins three and six are connected to two digital outputs from the microcontroller. Pins seven. The controller that drives the display is the Epson S1D15G10. Pins four and five are connected to the SCK and MOSI respectively of one of the mbed’s SPI ports to allow a clock signal and data stream to be passed to the display. there is no data returned to the microcontroller so the MISO pin from the SPI port is rendered redundant. The usage of push button is to act as a reset button for the device. For this display.

cpp’ C++ source file to contain the class and method for creating accessing the peripheral and a ‘.1 Device Drivers This section describes the design and implementation of the functions and classes that allow the microcontroller to interface with its peripherals.0 Software Design This section focuses on the process of writing the software to control the hardware of the device and the user interface.9. Device Drivers o Matrix Keypad Driver o LCD Display Driver o Buzzer Audio Driver Key Operational Modules o Input Processor o Command Interpreter o System Navigation and Status Functions o File Access Functions Main Mode Modules o Task Mode Interface o Free Mode Interface 9. 33 . a ‘. The main software components implemented are listed below.h’ C++ header file that contains the function prototypes and variable definitions of the device class. Each device has two source code files.

the system requires four row pins to read and four column pins to write. it was necessary to define digital inputs for each row and digital outputs for each column. Rather than reading and writing to each pin individually. This means that when an instance of the class is defined.These header files are included in the main function of the program to allow the main program to create connect to each individual peripheral. the pins for each column and row need to be specified and then are passed to the class as arguments of the class initialiser.1. In order to read from the rows and write to the columns. This means that a four digit binary ‘BusIn’ was required for the row input and a four digit binary ‘BusOut’ was required for the column outputxix.1 Matrix Keypad Design The microcontroller will sequentially drive each column high and then read the rows to check if any of the rows have been driven high by the column. The class initialises these bus objects by adding the pins passed to the class by the default constructor. In the case of this keypad. 9. Figure 19: Keypad Row BUS Example 34 . it is possible to create a ‘Bus’ of pins using the mbed library to allow binary string to be read or written to the bus and to each of the pins.

This means that the loop will perform four complete iterations before the function returns a value and each loop drives one of the columns high. the value ‘0x1’ is bitwise shifted left by the current value of ‘i’ and this will produce the desire effect of driving each column high in sequence. and a ‘read’ function that invokes the scan function and returns a character array (string) that refers to the specific button that is pressed.1 Scan Function The scan function defines an integer variable ‘value’ that is initially set to zero. For the second. The function uses a ‘for’ loop that increments an integer ‘i’ from zero to three incrementing by one each iteration. third and fourth iterations the column bus is sent the values ‘0010 0100 1000’respectively. and this variable is modified and is returned when the function is complete. The read function returns a character string rather than simply letting the driver return the binary results of the scan function as it will reduce code and increase the readability within the main function.The class uses two main functions to operate. A hexadecimal value of ‘0x1’ corresponds to the binary string‘0001’ and this value is be sent to the column bus in the first iteration in order to drive the first column high. A ‘scan’ function is used to drive each column high. 35 .1.1. read the value returned on the row bus and then return a unique value that corresponds to a particular button. The read function is defined as a public function so that it can be accessed from the main system function but the scan function is private and is only accessible by the read function 9. In order to do this for each iteration.

36 . If however the same row was driven high by the fourth column the value of ‘i’ at that point would be three. This would result in the output value of ‘0001000000000000’ which is unique for the button at column three row one.Figure 20: Column Driving Example Once a column is driven high. so the ‘0001’value would be left shifted by four times three so twelve bytes. the function will return zero. The final step of the scan function is to evaluate the row bus and assign a return value to the function. In order to distinguish between a row that is returned by one column and a row that is returned by another. the value returned from the row bus is bit shifted left by four times the current value of ‘i’. This means that if row one was driven high by column one. the value of ‘i’ at that point would be zero due to conditions described above. and the value returned would be ‘0001’ left shifted by four time zero so the final result value would remain as‘0001’. If at no point the value of any row is driven high. the system pauses for 10ms in order to give the signal time to propagate to the row input pin. As there are four columns with four bit possible row values. amounting to no key pressed. the maximum length of the returned result will be sixteen bit.

Figure 21: Column to Row Conversion Example 9. the corresponding hexadecimal value and the character array that the function will return. the value is then evaluated in a logical switch statement.1. Table4shows the value returned by the ‘scan’ function.2 Read Function When the read function is called. which allows the function to return values based dependant on the value of the variable been analysed.1. The return type of this function is a character array so the function will return a text string that identifies the button that has been pressed.1.1. it starts by calling the ‘scan’ function defined in section 9. Once the value of the variable ‘value’ has been set.1 and assigns the returned value to an integer named ‘value’. 37 .

9.1. and this can be evaluated by the main program so it can continue scanning the keypad until a valid key press is returned. It can also be seen that ‘X’ is returned when the button in column four row four is pressed and this value corresponds to the return key on the keypad.Return Value From Scan Function 0000000000000001 0000000000000010 0000000000000100 0000000000001000 0000000000010000 0000000000100000 0000000001000000 0000000010000000 0000000100000000 0000001000000000 0000010000000000 0000100000000000 0001000000000000 0010000000000000 0100000000000000 1000000000000000 OTHER Hexadecim al Equivalent 0x0001 0x0002 0x0004 0x0008 0x0010 0x0020 0x0040 0x0080 0x0100 0x0200 0x0400 0x0800 0x1000 0x2000 0x4000 0x8000 N/A Returned Character Array “1” “4” “7” “FORWARD” “2” “5” “8” “0” “3” “6” “9” “LEFT” “REPEAT” “ENDREPEAT” “X” “RIGHT” “@” Keypa d Colum n 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 N/A Keypad Row 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 N/A Table 4: Keypad Value Interpretation If the value returned by the scan function is not a member of the list above (for example zero for no key pressed) the function will return the ‘@’ character. 38 . as there are many functions required to allow the display to operate and display certain graphical objects for use with the LOGO language.2 LCD Display Drivers The LCD display driver is one of the largest modules in terms of code.

It sets the number of text characters that can be displayed in a column This variable sets the text colour on the display with an 24 bit integer This variable sets the screen background colour of the display with an 24 bit integer This variable specifies the number of visible pixels of the y axis on the display This variable specifies the number of visible pixels of the x axis on the display 39 _rows _columns _foreground _background _width _height Table 5: LCD Driver Variable Definitions . The values of the pins are then assigned to variables within the class.The display required a SPI port connection. SPI MISO. It is important to note that ‘reset’ and ‘chip select’ are both active low. It sets the current screen row of the text cursor This variable is used in the process of outputting text to the display. This meant that the default constructor for the display class needed to include pins for SPI MOSI. CS and RESET. It sets the current screen column of the text cursor This variable is used in the process of outputting text to the display. SPI SCLK. It sets the number of text characters that can be displayed on a row This variable is used in the process of outputting text to the display. The mbed library already has a class to handle serial interactions so the three SPI pins are assigned to an object of type SPI called ‘_spi’ (the underscore denotes that the variable is a private variable and non-accessible to functions outside the class). Variable Name _row _column Description This variable is used in the process of outputting text to the display. a chip select pin and a reset pin. There are a number of variables required to specify certain operational qualities of the device and these are listed and described in table 5. the chip select pin is assigned to a DigitalOut object called ‘_cs’ and the reset pin is also assigned to a DigitalOut object called ‘_rst’.

The next sections contain details about each of the functions required to operate the LCD screen. The LCD display uses a 9 bit serial interface. The data function is used to transmit serial data to the LCD display. 40 . the desired 8bit word that is due to be transmitted must be subjected to a binary OR with 0x100 (which corresponds to 100000000) so that the 8th bit will always have a value of 1.2. where the lowest 8 bits contain the desired data byte and the 8th bit contains the control flag.2. In order to make sure that the 8th bit is always 1 for a data transmission. the 8th bit needs to be set to 1 to indicate that the byte is a data transmission. the command is transmitted in a 9 bit interface however the 8th bit in this case is always zero to signify that the word is a command and not data transmission. the word to be written is subjected to a binary AND with 0xFF (which corresponds to 011111111) and this will leave the word unaltered but the 8th bit will always be zero.1. 9.1 The Data Function Form: void data(int value).1.2 The Command Function Form: void command(int value). In order to transmit data to the LCD. Similarly to the data function. This resultant value is then written to the SPI port using the mbed library’s ‘write’ function. The resultant value is then written to the SPI port using the SPI ‘write’ function. 9. To make sure that the 8th bit is always 0 for command transmission. The command function is used to transmit a serial command to the LCD display controller.

The select and deselect functions simply alter the value of the ‘_cs’ digital output port to either zero or one respectively. The function requires the specification of an initial x and y coordinate and the width and height of the window. Form: void _deselect(). data and synchronises the LCD with the serial port clock. int y. The chip select prepares the device to receive setup commands. This 41 .3 Select and Deselect Form: void _select().4 The Window Function Form: void window(int x. The function then calculates the number of addressable pixel rows and pixel columns of the window and also trims and offsets the coordinates based on the number of visible pixels on screen.1.1. int width. In the case of this display the initial y coordinate is offset by +2 and the final x and y coordinates have one pixel subtracted. The final stage of this function sends the command to the display to start writing to RAM (0x5C or 01011100).2. These are the memory locations that are accessed when the device reads memory in the page direction and the column direction. The eight bit command to write to the column register is 0x15 (00010101) and the command to write to the page register is 0x75 (01110101). The window function is used to create a graphical window area in memory which the software can write to.9. The resulting number of rows and columns are then written to the RAM of the display using the ‘command’ and ‘data’ functions. int height).2. 9.

4) to have each pixel filled with a specified 24-bit colour (which is converted to 8-bit on transmission). so the 24bit colour needs to be split into 8-bit segments. as the least significant bit is the transfer mode identifier (always zero for data from the previous section). This colour is passed to the device through the functions definition arguments.command allows functions that are called after this function to write information to the pixel memory of the locations defined by this window. Once this window is created.1. 9.From the controller datasheet.2. int height. Figure 22: LCD Colour Transmission Format xv This method of transmission is optimal for the fill command as the function is used to fill a relatively large number of pixels with the same colour.2. it is stated that the 24-bit colour data must be converted to three 8-bit words in the format shown in figure 22. The function invokes the ‘select’ function in order to prepare the LCD to receive data and then invokes the ‘window’ function with the dimension of the coloured window that is desired. int width. int colour). The serial connection uses a 9-bit interface. the colour needs to be manipulated so it can be transmitted to the device. and this method of transmission sends the colour information required for two pixels in one set of data transmissions. This means that pixel data only has to be sent for 42 . The fill function allows a window (from section 9.5 The Fill Function Form: void fil(int x. int y.1.

The colour needs to be bitwise shifted right by twenty. This produces produce an eight-bit word in the format RRRRGGGG. and then an OR operation is applied to the shifted value and the blue four-bit integer. These three values then need to be merged together into the transmission format specified above. 3. 2. and then an OR operation is applied to the shifted value and the red four-bit integer. In order to manipulate a 24-bit colour into the 8-bit format specified above. 1. twelve and four bits in order to obtain the four bit red.half the total number of pixels to be filled. a number of operations take place. and then an OR operation is applied to the shifted value and the green four-bit integer. The four-bit red value is bitwise left shifted by four. The four-bit green value is bitwise left shifted by four. The four-bit blue value is bitwise left shifted by four. green and blue colour values respectively. To do this. These three newly generated values are then written to the device memory a number of times equal to half the total number of pixels to be written. the total number of pixels would be ten and so the commands would be sent five times. This produces produce an eight-bit word in the format GGGGBBBB. The display data is acquired through the three data words in figure 22 and then the data of two pixels is written to the display RAM. This produces produce an eight-bit word in the format BBBBRRRR. a number of bitwise operations are performed. 43 . For example. if the fill size was a box five pixels wide by five pixels high.

int height. The function first calls the ‘_select’ function to prepare the LCD to receive data.5 with the desired x. The pixel function allows the specification of the colour of one particular pixel at a given screen coordinate. This function is particularly aimed at the text drawing capabilities of the system. const char* bitstream). int y. the system can draw a particular pixel with one colour or another. This function simply invokes the Fill function described in section 9. 9. and then calls the ‘_window’ function to create a writable area of screen with the position and dimensions specified in the function call.2. int width. 9. The bitstream function is a function that allows a number of pixels to be written to the screen with different colours.Once this write operation is complete. As in the fill function.6 The Pixel Function Form: void pixel(int x. The fill command could have simply been used with these parameters but it seems more useful to have a self-explanatory driver library for future use. specified by a binary character string.1.2.1.7 The Bitstream Function Form: void bitstream(int x. int colour). y and colour values.1. the data written to the screen will be written two pixels at a time to reduce the time for transmitting data to the display. 44 . By specifying either a one or a zero in the string. int y. The width and height are set to one so that only one pixel is affected. the ‘_deselect’ function is called to free the data line to the LCD for future use.2.

The current byte (section of four bits) being sampled for the first pixel. The current bit within that byte that is being sampled for the second pixel. Calculated by multiplying the current iteration number by two and applying the modulus of eight. For each loop of the iteration.In order for this function to work each bit of the bit stream must be evaluated in sequence. The function will need to analyse two bytes at a time due to the chosen method of data transmission. The current byte being sampled for the second pixel. Calculated by multiplying the current iteration number plus one by two and applying the modulus of eight. determining if the value of the particular bit is zero or one and output to the screen accordingly. Calculated by multiplying the current iteration number plus one by two and dividing by eight. 2. 3. Calculated by multiplying the current iteration number by two and dividing by eight. A logical FOR loop will incorporate the colour calculation process and data transmission process and will perform a number of iterations equal to half the total number of pixels to be written. four variables need to be calculated. 1. 4. 45 . The current bit within that byte that is being sampled for the first pixel.

An example is given in figure 24. These values can then be used to determine if binary value is a zero or a one. Each character in a character string consists of an 8-bit binary value and each character can be accessed independently within the string in the same manner as accessing an array. 46 . the result will only be one if the left most bit of the shifted word is one.Figure 23: Binary String Sampling Example The calculated variables give the exact location of the binary digit to be evaluated for the first and second pixel on each iteration of the FOR loop. By bitwise left shifting the current byte by the number of the current sampled bit and evaluating the resultant statement with ‘AND 0x80’ which corresponds to the binary value ‘1000 0000’.

2.5 and are joined for transmission in the arrangement shown in table6. and the text will always take the system default text colour.Figure 24: Binary String Manipulation Example The results of these calculations are then evaluated using a logical IF statement and if the value of the final byte is greater than zero. the current text colour is assigned to that pixel. This method of assigning colours was chosen as this function will be used to draw text to the screen.1. 47 . and if the value is not greater than zero. the current background colour is assigned. Both pixel colours are then manipulated into a 8-bit format in the manner described in section 9.

8 Text Functionality Displaying text is an important feature of this interactive device and there are a number of software components that were required to make the system function.2. the ‘_deselect()’ command is sent to the LCD. Once all of the pixels have been committed to memory.1. The LCD will not update the display until it has the complete colour data for a pixel so there is no danger of incorrect colour data being displayed.Data 1 R Pixel 1 R Pixel 1 R Pixel 1 R Pixel 1 G Pixel 1 G Pixel 1 G Pixel 1 G Pixel 1 Data 2 B Pixel 1 B Pixel 1 B Pixel 1 B Pixel 1 R Pixel 2 R Pixel 2 R Pixel 2 R Pixel 2 Data 3 G Pixel 2 G Pixel 2 G Pixel 2 G Pixel 2 B Pixel 2 B Pixel 2 B Pixel 2 B Pixel 2 Table 6: Multiple Pixel Colour Transition Format The pixels are written to the screen memory from top left row by row to the bottom right. 9. This function is crucial for ‘_putc()’ function that will be discussed in the next section and allows text to be written to the display. 48 . These main components are shown in figure 25.

2. A list of the formatting strings supported by the ‘printf’ function is given in table 7. The ‘printf’ function is a member of the standard C++ library and its purpose is to output a series of characters based on a format string.8..1.).Figure 25: Text Function Flow Diagram 9.1 The PrintF Function Form: void printf(“Formatting String”.variables. This function allows variables of different types to be converted to characters that are able to be output to the display and the recursively calls the ‘_putc’ function with the value of the character to be output. 49 ..

'INF'. Print a void * (pointer to void) in an implementation-defined format. the decimal point is not included on whole numbers. Also. 'G' uses upper-case letters. 50 . X o s c p n % Table 7: Printf Function Formatting Stringsxx For example ‘printf(“The Number is %i”. but write number of characters successfully written so far into an integer pointer parameter. if the value is zero. Print an unsigned integer in octal form. Print an unsigned integer as a hexadecimal number. This type differs slightly from fixed-point notation in that insignificant zeroes to the right of the decimal point are not included. 'x' uses lowercase letters and 'X' uses upper-case. E g. F Description Print an integer as a signed decimal number. Print a double value in standard form. Print decimal unsigned integer. Print nothing. Print a char (character). the exponent is 00. 'infinity' and 'nan' for 'f'. 'f' and 'F' only differs in how the strings for an infinite number or NaN are printed ('inf'. An E conversion uses the letter E (rather than e) to introduce the exponent. Print a literal '%' character. 'INFINITY' and 'NAN' for 'F'). G x. Print a character string. Print a double in normal (fixed-point) notation. The exponent always contains at least two digits. ‘prinf’ is the main function called from within the interface program to output text to the display.Character d.aNumber)’ where the variable ‘aNumber’ is equal to five would produce the output “The Number is 5”. whichever is more appropriate for its magnitude. Print a double in either normal or exponential notation. e. 'g' uses lower-case letters. i u f.

The letter E can be composed in an eight by eight grid as shown in figure 26.2.9.2 The Font Table The font table is an array of eight-bit hexadecimal values that contain the bitmapped data for each character that can be printed to the screen.8. The array is of type ‘unsigned char’ as this variable type is a byte in length (eight bits) and there 97 elements in the array which correspond to each character and one setup entry. the image can be converted to a binary sequence as show in figure 27. Each character has dimensions of eight by eight pixels so there are a total of 36 pixels per letter. 51 .1. Figure 26: Letter Bitmap Example By replacing each black cell with a one and each blue cell with a zero.

10000000. a custom version of this function needed to be written into the LCD display driver class.2.10000000.8.2. The ‘putc’ function is called for each character that is passed to the ‘printf’ function. In the case of E.00000000} The complete font table is given in appendix 13. as a majority of the display work has 52 .3 The PutC Function Form: virtual int _putc(int value).1 1 1 1 1 1 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Figure 27: Letter Bitmap Binary Example The result of this is a list of eight binary bytes that correspond to the eight rows of this particular letter. The overwritten function is relatively simple.10000000. The ‘_putc’ function is a member of the C++ standard libraryxxi but in order to make the ‘printf’ function work with the LCD display. 9.1.10000000.11110000.11111000. the entry in the font table corresponds to: {11111000. and its purpose is to output the received character to the display device.

so the maximum number of complete characters you can fit in either direction onscreen is 132px (screen size)/8=16 complete characters. The bitstream function is then called with the following parameters. From the display variables described in section 9. The maximum value of fifteen is chosen because each character in the font table is eight by eight pixels dimensionally. By multiplying these variables by eight.xxii The characters in the table from 0 to 31 are all system commands and not printable characters and these are 53 . This function calculates the starting ‘x’ and ‘y’ coordinate for each character and then reads the character bitmap from the font table and then calls the ‘bitstream’ function with those operands.1. the starting ‘x’ and ‘y’ position for the next character to be printed can be calculated.already been written in the ‘bitstream’ function described in the previous section. X position = (_column * 8) + 1 (+1 is added to space between the previous character) Y Position = (_row * 8) + 1 (+1 is added to space between the previous character) Height & Width = 8 as the font table characters are eight by eight pixels Bit Stream = The value of characters in the font table at position character value-31. The value that is passed to this function is an integer that relates to a specific character in the ASCII (American Standard Code for Information Interchange) table and there are a total of 128 possible values in the range from 0 to 127.2it was stated that the ‘_column’ and ‘_row’ variables store the current text position in a range from zero to fifteen.

the screen is cleared. and the ‘_column’ variable is incremented. Once the ‘bitstream’ function has been called. the character is output to the screen.5 The Locate Function Form: void locate(int column.8.4 The NewLine Function Form: void newline(). If ‘_row’ is greater than the maximum number of rows.1. 9.8.2. The locate function allows the specification of the screen row and column variables to position the text cursor for its next character. The function sets the ‘_column’ variable to zero which moves the cursor to the first column of the row and then increases the ‘_row' variable by one. int row). Finally.1. There is a small amount of logic at the end of the function to increment the ‘_row’ variable if the number of columns is greater than the maximum number of columns and also if the number of rows exceeds the maximum number of rows. The row and column 54 . 9. the screen is cleared and the ‘_row’ variable is set to zero.2. The font table I have created only has characters in the range 32-127 and this is why the 31 is subtracted from the initial value to make the first character in the set (the space character) correspond to the first element in the font table.not required for this device. the initial value that was passed to the function is returned to the ‘printf’ function to indicate that the character has been output successfully. The sole purpose of this function is to act as a line break for the text output of the system.

2. These functions are simply setter functions that allow the software to set the colour of text (forecolour) and the screen background colour.10 The Cls Function Form: void cls().9The Foreground and Background Functions Form: void foreground(int colour).2. The ‘_deselect’ function is called to free up the data line and the reset pin is driven low to perform a hardware reset. They both accept an integer value and the function can only be called from within the class definition file. The screen is cleared by issuing a function call to the fill command with ‘x’ and ‘y’ coordinates both equal to zero and width and height equal to the dimensions of the screen. 9.2. The cls function is used to clear all objects from the screen and set the text cursor to first row and the first column of the screen.values must be in the range zero to fifteen as there is a limit of sixteen characters per row or column. The SPI port is readied for 55 . 9. and this is blue by default. The fore colour is set to white and the back colour is set to blue by default. Form: void background(int colour).1. The reset function is the setup function for the display to prepare the device for operation. 9.11 The Reset Function Form: void reset().1. The area is filled with the colour that is currently stored in the ‘_background’ variable.1.

data(0x00). and these commands and data attributes are described in table 8. data(0x02). command(0x94). Function Call command(0xCA). data(39). command(0xAF). There are a number of setup commands that are required for the correct operation of the display. data(0x0). data(0x20). Description This command tells the LCD that it is about to receive data relating to the display control This data tells the display control that it has two divisions with a switching period of eight This data specifies the number of display lines = 32 (from 132/4 -1) This data states that there will be no inversely highlighted lines on the display This command tells the LCD that it is about to receive data relating to the common output scan direction This data tells the display to scan directionally from 1>80. data(3). data(0x00). command(0xBB). normal turn of the column address and the address scan direction is set to the column direction. command(0xD1). This command tells the LCD to prepare to receive data related to the voltage control parameter This data sets the display contrast setting to 0. 81<-160 This command enables the internal oscillator This command tells the LCD to exit sleep mode This command tells the LCD to prepare to receive commands related to the Power Control This data tells the LCD to turn on the voltage regulator. data(0x0). This data sets the RGB arrangement of the segments to default This data contains the gray-scale setup and sets the display to 16 gray-scale display type A This command turns the display on Table 8: LCD Display Setup Commands 56 .communication by setting its format is to 9-bit as this is the format in which the controller operates and the SPI frequency to 5 MHz. command(0x81).63% This data sets the display resistance ratio to three This command prepares the LCD for receiving data control information to set the display mode This data means normal display of the page address. data(0x0F). The reset pin is then driven high and the ‘_select’ command is called to prepare the LCD controller for data. command(0x20). data(0x1). circuit voltage follower and enable the voltage booster. command(0xBC).

the gradient of the line is sampled to see if the change in ‘y’ position is greater than the change in ‘x’ position. The reason for these interchanges are to do with the elimination of negative numbers when it comes to drawing the output to screen as will be discussed later. There are several operations that are initially performed on the two sets of coordinates before any output takes place. int y0.1. A logical FOR loop is then initiated with a number of iterations equal to the number of pixels between the first and final ‘x’ coordinate. The ‘pixel’ command is invoked to write pixels with colour specified within the function operands to the screen and is called during each iteration of the loop. If ‘x0’ is greater than ‘x1’ then ‘x1’ and ‘x0’ are swapped and ‘y1’ and ‘y0’ are swapped. 9. Firstly. int y1. The change in ‘x’ and change in ‘y’ values are then calculated as well as an error variable to account for any rounding errors in the ‘delta x’ value.2. int colour).12 The Line Function Form: void line(int x0. int x1.After the successful execution of all the commands listed in table 8the ‘_deselect’ command is called to free the data line and the ‘cls’ function is called to fill each pixel with the default background colour. a variable ‘ystep’ is assigned a value of one or minus one accordingly. The line function allows all pixels between two sets of screen coordinates to be filled with a specified colour. If this is the case then the ‘x0’ and the ‘y0’ coordinates are swapped and the ‘y1’ and ‘x1’ are swapped. This ‘ystep’ value will help in error correction later. The final evaluation to take place is whether the line is increasing or decreasing in the ‘y’ direction and based on this. The ‘error’ variable is 57 .

Figure 28: Line Error Compensation Example 9.also evaluated during each iteration and is reduced each time by the value of ‘deltay’. Lists of the variables that are initialised are given in table 9. 58 . the value of the next ‘y’ coordinate to be written is incremented by the value of ‘ystep’ and the error value is incremented by the value of ‘deltax’. This change in the value of ‘y’ allows the line to be drawn at angles which is crucial for many of the LOGO drawing commands. This function is used to initialise the class variables and the display.2.13 The Class Default Constructor The default constructor is called when the main program creates an instance of this device driver class. If the error value is less than zero.1.

Sets the text colour of the display to white background(0x0000FF). Specifies the height of the display in pixels as 132 Foreground(0xFFFFFF). Sets the current LOGO drawing colour to white penstate=1. Specifies the width of the display in pixels 132 _height = 132. For x-coordinate rotation: (x*cos(angle*(π/180)))-(y*sin(angle*(π/180)) 59 . The formulae to rotate the two points in an anticlockwise direction are given below. characters to sixteen _width = 132. Sets the current LOGO penstate to PENDOWN penscale=5. 66 (centre) pencolour=0xFFFFFF.2.Description Sets the current text cursor row to zero Sets the current text cursor column to zero Sets the maximum number of vertical text characters _rows = 16. The rotate command allows a pair of coordinates to be rotated about the x-axis by a given number of degrees. The ampersand preceding the ‘x’ and ‘y’ integers signify that the function is ‘passed by reference’ and performs the operations on the passed variables in memory so that it is changed rather than the function returning resultant values. to sixteen Sets the maximum number of horizontal text _columns = 16. int &y. _column = 0.1. Table 9: Default Constructor Variable Initialisations Finally the ‘reset’ command is called to initialise the LCD display. to 66 (centre) Sets the current vertical position of the logo turtle to ypos=66. Sets the number of pixels to a LOGO unit to five Command _row = 0. float angle). Sets the display background colour to blue Sets the current horizontal position of the LOGO turtle xpos=66.14 The Rotate Function Form: void rotate(int &x. 9.

This produces an arrow in the form shown in figure 29. The arrow consists of two lines with starting coordinates at (0. The turtle is drawn on screen at the location defined by the ‘xpos’ and ‘ypos’ variables so when the two lines are drawn. This function is used to draw an arrow shaped object to represent to the LOGO ‘turtle’ during graphical operations.0) and end coordinates at (3.-3) and (-3.1. this arrow can be rotated by a number of degrees so the tip points in a different direction.-3). float angle). 9.For y-coordinate rotation: (x*sin(angle*( π/180))))+(y*cos(angle*( π/180))) This function is used by many of the LOGO functions. the initial coordinates for both lines are set to the current values of these coordinates and the final coordinates are set to the sum of the line end point ‘x’ components and the ‘xpos’ 60 .15 The DrawTurtle Function Form: void drawturtle(int colour. Figure 29: Turtle Drawing Example By rotating both sets of coordinates by a give angle supplied to the function as an operand. This can be done by sending both sets of coordinates to the ‘rotate’ function and allows the user to visually see the current angle of rotation of the ‘turtle’.2.

61 .variable and the difference between the current ‘ypos’ variable and the line end point ‘y’ components. The function also allows the specification of the line colour and this allows turtles from old positions to be removed with ease.

2 LOGO Command Software 9.1 The Scale Function Form: void scale(int sc). 9.2 The Unscale Function Form: void unscale().2. 9. The ‘setbg’ function first evaluates if the colour supplied as the function is white as if this is the case the text display colour needs to be changed so it displays against the background.3 The Centre Function Form: void centre().4 The Setbg and Setpc Functions Form: void setbg(int col).2. This function sets the ‘xpos’ and ‘ypos’ variable to their default centre screen value of 64. This function sets the ‘penscale’ variable to its default value of five pixels per unit.9. The ‘setpc’ function simply sets the ‘pencolour’ variable to the value of the operand passed to the function. 9. This function sets the ‘penscale’ variable used within the system to determine the number of pixels that one unit of the LOGO language corresponds to. Form void setpc(int col).2. This is done by calling the ‘foreground’ function and 62 . These functions allow the screen background and drawing pen colour to be set to integer colour values.2.

and then a call to the ‘reset’ function is made. For the ‘setleft’ function. The ‘background’ function is then called with the supplied function operand.2. 9. the turtle faces directly up with an angle of zero degrees. These functions allow the current angle of the LOGO ‘turtle’ to be altered.6 The SetLeft & SetRight Functions Form: void setleft(float angle). the new angle is simply added on to the current angle otherwise the angle is set to the angle specified in the operand of the function. 63 .setting it to black. The ‘cls’ function is then called to clear the screen and to display the new background colour. there is a logical check to see if the current ‘turtle’ angle before rotation is zero or not. a call is made to the ‘drawturtle’ function with the angle of the turtle before rotation and the colour of the display background. If not. This function resets all of the LOGO drawing properties to their default values and then clears the entire screen. The values are set to default by invoking the same variable definitions defined in the LCD display default constructor section. Initially.2. 9.5 The Clear Function Form: void clear(). When either function is called. The ‘setleft’ command rotates the ‘turtle’ anticlockwise and the ‘setright’ command rotates the ‘turtle’ clockwise. This will have the effect of removing the old turtle from the display. Form: void setright(float angle).

the new angle is simply subtracted from the current angle but if otherwise the angle is set to 360 minus the angle specified in the operand of the function. 9. 64 . This function tells the driver whether or not to leave a trail following the movements of the LOGO ‘turtle’. 9.7 The SetX and SetY Functions Form: void setx(int x). If not.2. This is done by setting the value of the ‘penstate’ variable to the value of the supplied integer operand. there is also logical check to see if the current ‘turtle’ angle before rotation is zero or not. A value of zero signifies that the pen is up and a trail should not be left and a value of one signifies that the pen is down and a trail should be drawn. These functions allow the setting of the ‘xpos’ and ‘ypos’ variables that store the current ‘x’ and ‘y’ locations respectively of the LOGO ‘turtle’. the angle is the new angle of rotation and the colour is the current drawing colour of the LOGO system.2. the ‘turtleangle’ variable is updated with the new angle of rotation. These variables accept a maximum value of 132 as that is the number of pixels available on either axis of the display.For the ‘setright’ function. Form: void sety(int y). Once these calculations have taken place. and the ‘drawturtle’ command is called once again but this time.8 The SetPenState Function Form: void setpenstate(int state).

If the ‘penstate’ variable is set to 1 (pen down). The ‘dir’ direction variable is then checked and if the value is zero. the ‘dist’ value is multiplied by minus one to signify that the ‘turtle’ is travelling in the opposite direction. The function checks that the current pen state is pen down. The first operand ‘dir’ taken by the function is the direction integer. The move function is used to move the LOGO ‘turtle’ forwards or backwards around the screen.2. invokes the line function. The second operand ‘dist’ tells the function the number of LOGO units that the ‘turtle’ should move in the given direction. Firstly.9 The Move Function Form: void move(int dir. and if so. int dist). This multiplication will supply the number of pixels for the ‘turtle’ to travel and give the end coordinates of the line. These coordinates are then rotated by the current turtle angle using the ‘rotate’ command and are ready to be drawn to the display. and a value of one tells the function to move forward in the direction that the ‘turtle’ is facing and zero tells it to move backward in the opposite direction to which it is facing. A set of coordinates are then created with an initial x-coordinate of zero and a y-coordinate of the multiple of the ‘dist’ variable and the LOGO ‘penscale’ variable. a line will be drawn between the initial and new location of the ‘turtle’. the ‘drawturtle’ function is invoked with the background colour and current turtle angle as operands and the old ‘turtle’ is removed.9. with the starting ‘x’ and ‘y’ location as the current ‘xpos’ and ‘ypos’ variable values respectively and the final ‘x’ and ‘y’ coordinates as the sum of the 65 .

the ‘line’ command is skipped. The final step is to draw the new position of the ‘turtle’ by invoking the ‘drawturtle’ command with the current turtle angle and current LOGO pen drawing colour. A delta error variable needs to be used as in the ‘line’ function to allow the ‘y’ value to change programmatically with ‘x’ and maintain the circular shape. The circle function allows the user to draw a circle on screen with a specified integer radius. The pixels around the circumference of the circle are coloured one at a time programmatically. 9. This value is initially set as 3-(2*radius).final line x-coordinate and the ‘xpos’ variable and the difference between the current ‘ypos’ variable and the y-coordinate of the final line coordinates respectively. Once this output is complete. The number of pixels that the radius corresponds to is dependent upon the current ‘penscale’ parameter (default five).10 The Circle Function Form: void circle(int radius).2. the ‘xpos’ variable is updated by adding the ‘x’ operand and the ‘ypos’ variable is updated by subtracting the ‘y’ operand. 66 . If the penstate is pen up. Figure 30: Move Function Translation Example The reason for subtracting the y-coordinate from the ‘ypos’ variable is due to the fact that the screen y-axis runs from top to bottom.

the value is incremented by (4*(x-y)) + 10.A logical WHILE loop handles the repetition of the pixel writing functionality. 67 . If the value is less than zero. X Coordinate xpos + x xpos + y xpos – x xpos + y xpos – x xpos – y xpos + x xpos . If the value is not less than zero. and the value of y is decremented. and during one pass. the pixels in table 10are written. The pixels are coloured using the integer value stored in the LOGO ‘pencolour’ variable. The value of ‘x’ is then increased by one and the next iteration begins. it is incremented by (4*x) + 6 where ‘x’ is the current value of the variable in the while loop.y Y Coordinate ypos + y ypos + x ypos + y ypos – x ypos – y ypos – x ypos – y ypos + x Table 10: Circle Function Pixel Drawing Locations At the end of each iteration the delta error value discussed earlier is reevaluated.

68 . In order to connect the speaker to the microcontroller. where middle C is defined as note 60. the positive wire of the speaker is connected to one of the PWM output pins on the mbed. The speaker will be driven by the mbed’s PWM port using the functions described in the interface definition section. By changing the period of the signal. This specification includes 128 notes spread across ten octaves.3 The Buzzer Driver The buzzer driver is designed to oscillate a magnetic driven speaker at various frequencies in order to produce a range of musical notes. As discussed in the interface section. note numbers and their corresponding frequencies are given in appendix 13. The notes in the MIDI specification are identified by a note number. The notes that I have chosen to use are those included in the MIDI (Musical Instrument Digital Interface) specification. a connection is created in the software to this output using the ‘PwmOut instanceName(pinName)’ command.9. The full list of the notes. and in this case. the PWM output pin is p21. the speaker can be made to oscillate at different frequencies and therefore produce different notes. The pulse width modulated signal causes the speaker to produce a sound as the signal varies between on and off and cause the magnet driving the speaker to oscillate.3.

The function first checks that the supplied note number is in the range 0 to 127 to make sure that it exists within the MIDI note specification. so the period of the PWM signal is set to 1. the ‘wait_ms’ function is called which allows the system to pause for a given number of milliseconds using the user inputted time as the operand.0/Note Frequency. the duty cycle is set to 0%.3. When the wait command expires. float time).9.1 The Beep Function Form: void beep(int note. This is because in order for the speaker to oscillate it must spend an equal amount of time on to off. If the note is within range. 69 .xxiiiThe duty cycle is the ratio of time high to time low of the PWM signal and for this application is set to 50%. The purpose of this function is to receive a MIDI note number and note duration (in milliseconds) from the user. The speaker will continue to sound throughout this delay. effectively turning the speaker off. the function calculates the required period of the PWM signal by retrieving the frequency of that note number from a predefined array. The period of a wave is defined as the reciprocal of the frequency. and output the note to the speaker. Figure 31: PWM Duty Cycle Example Once the output has been sent to the speaker.

Allows the system to terminate when the max number of commands has been reached.p26.p7. This allows all of public class functions to be accessed from the main program. This integer specifies the maximum number of commands that can be entered in one go.p8. These values are given in table 11.p29) (p20) (p19) (p18) (p16) “local” DigitalOut DigitalOut DigitalOut DigitalIn LocalFileSystem red blue green s2 local Buzzer buzzer (p21) Const int Cmax 40 int theCount 0 Table 11: User Interface Class and Variable Definitions 70 .p27. Variable/ Class Name lcd Variable/Class Type Variable/Class Operands Description Creates an instance of the NokiaLCD driver class called ‘lcd’ and passes the mbed pins to the class.p9) Keypad pad (p28.4 The User Interface Software The user interface contains a number of functions that support and facilitate interaction with the users of the system. Creates a connection to the local file system class which allows file access to data stored on the internal flash memory from the main program. This integer stores the current number of commands that have been entered into the system. Defines a digital input connected to the second push button on the LCD.p23. This allows the main program to access the buzzer functions. Defines a digital output pin connected the the ‘green of the LCD tri-colour LED. Defines a digital output pin connected the the ‘red’ of the LCD tri-colour LED. The user interface has a number of variables and class instances that need to be defined.9.p6. This allows use of the keypad functions from the main program. p24. Creates an instance of the Keypad driver class called ‘pad’ and passes the row and column pins to the class.p25. Creates an instance of the Buzzer class called ‘buzzer’ and defines the pin of the PWM port used. Defines a digital output pin connected the the ‘blue of the LCD tri-colour LED.p22. NokiaLCD (p5.

1 The LEDR. The LEDs are all active low. By placing the code to do this into functions. the screen is cleared using the ‘cls’ display command. As all three of the LEDs are mounted in a very close proximity. The system will continue to invoke the ‘read’ function until a key press is detected. the ‘read’ function returns the ‘@’ character. the pins for the remaining two LEDS are driven high. When no key is pressed. the system can detect if any other key is pressed. so in order to turn an LED on the digital output that they are connected to must be driven low.2 The Wait for Key Function Form: void waitForKey(). 71 . only one of the LEDs must be enabled at one time. and the loop is broken allowing the next interface function to proceed. 9. This function allows the system to pause and wait for a key on the keypad to be pressed. This means that when any of the functions are called. When this occurs. This is performed by initiating the ‘read’ function of the keypad class and then analysing the variable returned. it minimises the number of lines of code in the main program as three lines of code are replaced by only one. LEDG & LEDB Functions Form: void LEDR().4. These functions handle the operation of each colour present in the LCDs tricolour LED.4. and for visual clarity. By comparing the returned value to this character. Form: void LEDG().9. Form: void LEDB().

the nine digit integer modulus 1. 1. the nine digit integer modulus 1. green and blue component parts. The LCD colour functions accept 24-bit hexadecimal values.000 to remove the blue components using the same integer truncation as in the red component.000. This is done using mathematical integer operations as follows.4. This will give a float value in the form RRR. The standard LOGO command specification states that colours should be entered in a RGB format with each component value having a maximum number of 255. 72 .000 is taken to remove both the red and green components. leaving only the red components.9.GGGBBB but as the variable is of type integer. 3.000. To obtain the red component. the nine digit integer is divided by 1. and the input numbers need to be converted to this form. This function is used to convert a colour input by the user to a colour that can be passed to the LCD display functions. This means that the numbers passed to this function will have a maximum value of 255255255 and a minimum value of 000000000. 2.000 is calculated in order to remove the red component digits and then the result is divided through by 1. The function receives the three colour components in the form of a single integer and the first step is to split this number into red. leaving only the blue.3 The getColour Function Form: int getColour(int v). To obtain the green component.000. the values after the decimal point will be truncated. To obtain the blue component.

2X’ as the formatting string. Each integer colour value is then converted to a hexadecimal value string using the ‘sprintf’ function with ‘%. the hexadecimal string is converted back to an integer using the ‘strtol’ function which allows a character string to be converted to a long integer. Figure 32: RGB Colour Conversion Example 73 . The conversion process is shown in figure 32. The base is specified as sixteen as the number is hexadecimal.The results of each calculation are stored in variables for later use. Once this conversion has taken place for each colour and the results have been joined.

These sub functions are used to print the executed commands at the bottom of the screen so that the user can see the commands being executed in real-time. This function is the main brain of the LOGO part of the software as it converts the commands that are entered by the user to system functions that control the device hardware. Using this functionality. The function also receives an integer value which is used passed to the called functions if required. one of two sub functions will be called. the command that is passed to the function is compared to a list or predefined commands and when the command matches a predefined command. int value).This integer value is then returned to the function that requested the conversion to be used elsewhere. 74 . the functions that are called and the type of command printing that takes place. returning zero if the two character strings are equal or a value greater or less than zero if the strings are not equal. The functions differ only in the fact that one prints a command and a command operand integer and the other only prints the command. The function consists of a number of logical if statements with conditions that invoke the ‘strcmp’ function. a set of functions are executed. 9. Once the function specific commands have been executed. This function compares two character string character by character.4. Table 12lists the commands that the system is pre-programmed to receive.4 The Interp Function Form: void interp(char* cmd.

move(1. The ‘PENSTATE’ command uses a logical switch statement to evaluate the current LOGO ‘penstate’ variable when the function is called and then inverts the current value.value) Lcd.setleft(value) Lcd.setright(value) Lcd. both the note number and note duration are contained within the same integer.centre() Print Type With Variable With Variable With Variable With Variable With Variable With Variable With Variable No Variable With Variable With Variable No Variable With Variable No Variable Table 12: Interpreter Function Calls There are two functions that are not listed in the table and this is due to the complex nature of their function calls.scale(value) Lcd. The note number can vary from three digits to one digit and the duration in milliseconds can vary from four digits to one digit.circle(value) Lcd.clear() Lcd.Command Received FORWARD BACKWARD LEFT RIGHT SETX SETY SCALE UNSCALE SETBG SETPC CLEAR CIRCLE CENTRE Functions Executed Lcd. When this inversion occurs. A mathematical algorithm was devised to 75 .unscale() Lcd. The ‘BEEP’ command uses some mathematical manipulation in order to retrieve the desired information from the value integer that it receives. This is done using the ‘getpenstate’ function which returns either a zero or a one to signify the current pen state. the text that is printed is not the ‘PENSTATE’ command but either ‘PENUP’ or ‘PENDOWN’ depending upon the new state.setpc(getColour(value)) Lcd. As the value operand attached to each function can only be a single integer.move(0.setbg(getColour(value)) Lcd.sety(value) Lcd.value) Lcd.setx(value) Lcd.

the system pauses for one second to allow the end user to view the commands as they are being processed. The purpose of this function is to load a set of teacher defined commands from a file stored on the mbed internal flash memory and copy the loaded commands into an array in system memory.000 to remove the lowest 4 digits via integer truncation. The duration is then be calculated by simply taking the modulus of the value and 10.5 The LoadFile Function Form: void LoadFile().beep’ function and the tone is produced. After each interpreter command is executed. and then applying the modulus of 1. Figure 33: Beep Function Operand Specification The leading digit is required as during the transfer of commands from memory. the note number is extracted by dividing the value by 10. These commands are then passed to the ‘buzzer.000 to remove the leading nine.extract the desired data from this form. The format of the data within the single integer is shown in figure 33. With the data in this form. and it is difficult to retain leading zeros in each format and a fixed numerical length is required by the decoding algorithm. the data changes formats. screen and disk. 9.000.4. The process starts by changing the LCD tri76 .

A connection to a physical file named ‘fp’ is created using the ‘FILE’ keyword and calling the ‘fopen’ command. the file path will be ‘/local/EXERCISE. it was decided that a structure (struct)would be used. Figure 34: Command Storage and Separation Example 77 . In order to store loaded data from the disk efficiently in system memory.colour LED to blue to indicate that the system is busy and displaying ‘LOADING EXERCISE’ on the display. The Structure contains two instance variables.An example of how this structure stores entered data is shown in figure 34. a ‘CMD’ character array with length 10 to store the loaded commands and a ‘NO’ integer to store the associated operands. the C++ standard library file access functions can be called.TXT’ where ‘local’ is the name of the ‘LocalFileSystem’ object that was created and ‘r’ is the type of data access as the file only needs to be read. This command takes two operands. An array instance of this structure called ‘info’ is created and it has a number of elements equal to the maximum number of commands enterable to the system (defined by the ‘Cmax’ variable). the path to the file and the type of access it requires. Using the instance of the ‘LocalFileSystem’ class defined in the variables section. For this system.

strings (commands) and integers (operands) can be read respectively.destination_variable)’ xxiv where the formatting string refers to a character string using the same keywords as in the ‘printf’ function and the destination variable is where any qualifying data should be copied. By inserting two of these commands within the WHILE loop. one for strings that has a destination of the ‘CMD’ variable of the info structure and one for numbers that has the destination of the ‘NO’ variable of the info structure. and this also tells the system which element within the info array to save the read data to. and placing this function within a logical WHILE loop which compares the function result to Boolean one. This function takes the form ‘fscanf(file_object. Another useful C++ standard library function allows certain data types to be found within a file and copied accordingly. the data can be read from the file and into system memory. A ‘COUNT’ variable is used to record the current iteration number of the WHILE loop. a number of commands can be executed while the file still has unread data. 78 . By calling this function with the ‘file_object’ set as the ‘fp’ file connection created earlier. By setting the formatting strings to ‘%s’ and ‘%d’.formatting_string.The ‘feof(file_object)’ function returns a boolean value of one when any method accessing the file defined in ‘file_object’ reaches the end of the readable file data.

Figure 35: Command Separation and Storage Example for a Given Iteration Once complete. If the total count is zero.6 The Task Function Form: void TaskFunction(). This function has now loaded all of the information required for the systems task mode to operate. the system displays an error message ‘No Items Were Loaded’. If the total count is greater than zero a message is displayed which states ‘This task has X steps’ where ‘X’ is the number of commands loaded by the system. The system then counts the number of commands that the system has read by checking that each command of the info structure has a length greater than one character. the connection to the file is closed using the ‘fclose(file_object)’ command and the tri-colour LED is changed to green to show that the system is idle. 9. 79 .4.

Save CmdCount Table 13: Task Function Variable Definitions 80 . The input routines a. Command and integer input c. An array with length set to the maximum number of commands that can be entered to store any entered commands in memory. 1. Used to store the current number of commands that have been entered.The task function is the main interface routine for the section of the device which handles the completion of a teacher set exercise by a pupil. Stores numbers converted from the ‘Val’ variable as integers. The saving routine A number of variables are required throughout this function and these are declared and initiated before any user interaction. Command only input b. Beep command input d. An array with length set to the maximum number of commands that can be entered to store any entered command operands in memory. Variable Name Val No COUNT SaveI Variable Type Character array (char*) Integer Integer Integer Array Array of Character arrays (char*) Integer Description Temporally stores the character array returned from the keypad ‘read()’ function. The marking routine 3. Colour command input 2. These variables are described in table 13. Records the number of digits input in each input subroutine. This function has three main sub-routines.

This allows the user to skip the command input process without needing to enter the total number of required commands. the integer value 9 is saved and makes the subsequent code easier to understand. The ‘X’ value indicates that the return key has been pressed. By subtracting 48 from the ASCII integer value returned from the function. The system checks that the character returned is not the ‘@’ character. By subtracting 48 from this value. and the value returned is assigned to the ‘Val’ variable. the character ‘9’ in the ASCII table has a value of 57. the system asks the user whether they have finished entering commands and wish to terminate the process.4. a numerical representation of the key pressed can be found and this number is assigned to the ‘No’ variable. The ‘E’ value represents the first character of the ‘ENDREPEAT’ command and if this is the case. as this corresponds to no key pressed and then continues. The keypad is read using the ‘read’ function. 9. the system proceeds to save the command without an operand. This command is treated differently to the other commands as it is the only one that does not share its button with a numerical value and doesn’t require an operand.6. For example. The command input process is nested within a while loop which will keep iterating until the ‘break’ command is called.1 The Input Routine This routine handles the process of taking user input and placing it in the system memory using variables described in the previous section. The first character of the ‘Val’ variable is analysed to see if it is equal to either ‘X’ or to ‘E’. 81 . and if this is the case.By default each of the members of the ‘Save’ array are set to a single space character and the members of the ‘SaveI’ array are set to zero.

) and some require operands to be entered in different formats.The ‘No’ variable is then analysed to check that the numerical value is less than or equal to nine. Figure 36: Interpretation of Keypad Commands The ‘FORWARD’.g. they do not need to be pre-processed. Due to this requirement. and as these commands all require numerical input and already have a ‘Val’ value equal to their command. 82 .’BACKWARD’. An example of this process is given in figure 36. so they are not processed by the above method. the ‘Val’ variable content is replace with the command that that string represents.’LEFT’ and ‘RIGHT’ commands do not share a key with a number. as this tells the system that one of the numerical key commands has been pressed. PENSCALE. The system is designed to request an operand from the user unless otherwise specified. Not all functions require an operand to be entered (e. there are several numerical input methods that can be called to accommodate these needs. For each number.

and exits the loop only when the ‘break’ command is called after the entry of three digits. The system iterates and when a numerical input is received. the system invoked the ‘atoi’ function.2 Commands With Operands For commands that require an operand the entered command is written to the ‘Save’ array in the same manner as commands without operands. each digit is assigned to an element of the ‘trash’ character array.6.4. The ‘CmdCount’ variable is the incremented and the command input process starts again from the beginning.1 Commands Without Operands For commands that do not require operands the command is printed to the screen and the value of the ‘Val’ variable is copied to the ‘Save’ array at the location equal to the current value of the ‘CmdCount’ variable. a string termination character ‘\0’ is required. and this terminates the input process. A character array named ‘trash’ with four elements is used to store the entered digits. When all three digits have been input.1. Using a while loop. The default number of digits for a command operand is three. which allows an array to be converted to an integer value.1.4. The ‘SaveI’ array at the same index location is set to zero.6. The user can also press the return key after entering at least one digit. These digits are stored in a temporary location until all three digits are entered and the final value can be written to the memory variables. This value is then assigned to the ‘SaveI’ array at the current element of index equal to the 83 . the system loops and scans the keypad for input in the same manner as the command input. The reason for four elements instead of just three is that in order to store the digits within a character array. so the system will accept three digit inputs from the keypad. 9.9.

The LOGO specification defines colour values in the form RRRGGGBBB and so this is the format that the user will enter data. This gives the user the simple interface shown in figure 38. Once the first three digits have been entered.‘CmdCount’ variable. Before the first set of three digits is entered.6. The break command is then called and the system returns to the beginning of the command input process. Figure 37: Temporary Storage for Numerical Input Example 9. the ‘G’ character is printed and after six characters the ‘B’ character is printed.3 Colour Input The colour input routine allows the user to enter colour data in a simple and easy to understand format.6.1.2but with a few minor changes. The number of elements that the temporary character array ‘trash’ holds is increased to ten.1. The actual data input process is practically the same as the method defined in 9. as there are nine colour values to enter as well as one escape character. An example of this storage process is shown in figure 37. the LCD ‘newline’ function is called and the ‘R’ character is printed to the display.4.4. 84 .

1. the system once again coverts the ‘trash’ array to an integer value and saves it to the ‘SaveI’ array. the string termination character and a leading digit for use in the decoding algorithm described by the beep driver class.6. 9. the beep input is merely a tailored version of the command with operand input routine. The ‘BEEP’ command requires the input of a note number in the range from 0 to 127 and duration in milliseconds. The resultant interface is shown in figure 39. In this instance. the ‘trash’ array has nine elements to account for the three digit note number. When these three characters are entered.4 Beep Input As with the colour input. and the next three numbers are proceeded by a ‘Note: ‘ string. The command input process then commences for the next command. The first element of the ‘trash’ array is always set to ‘9’ due to the algorithm specification. 85 . four digit duration.Figure 38: RGB Colour Input Format Once all nine characters have been input. the ‘newline’ LCD function is called and ‘Duration: ‘ is printed to the screen.4.

Two integer variables called ‘total’ and ‘correct’ are used to keep track of the users marks. 9.2 The Marking Routine The purpose of the marking routine is to compare the commands and operands entered by the user during the input routine to those commands that are loaded by the ‘FileLoad’ function. The answers are checked by using the ‘strcmp’ function to check the users commands stored in the ‘Save’ array and the loaded commands stored in the ‘info.6. only one mark is attributed to it. The work is visually marked by printing the user’s answers to the screen with correct answers written in green and incorrect answers written in red.CMD’ structure array. each command can have a maximum of two marks. the command input process resumes for the next command. The ‘total’ variable counts the number of possible marks that the user can obtain and the ‘correct’ variable stores the number of answers that were correct. In general.Figure 39: BEEP Command Input Example Once all seven digits have been input. The operands are compared simply by performing a 86 .4. If the command does not require an operand. one for the command and one for the command operand.

Figure 40: Marking Variable Adjustment Example In the case that a ‘BEEP’ command was entered by the user 9.000 is subtracted from the command operand as this will remove the leading ‘9’ digit added for the decoding algorithm in order to not confuse the user. To deal with this. The divisibility by thirteen is important it is the 87 . a logical IF function is used to evaluate if the total number of commands is greater than fifteen and if the current command number is also divisible by thirteen and greater than zero. If the number of commands entered by the user is greater than fifteen. the text colour is changed to green using the LCD ‘foreground’ command with the colour ‘0x00FF00’ and then the ‘correct’ variable is incremented by one.NO’ structure array. The ‘total’ variable is incremented by at least one for each iteration but is only increased twice during an iteration if the value of the loaded command operand is greater than zero. An example of these variable changes is shown in figure 40. the screen will not be able to display all of the answers on screen at once.000.logical equals of the user answers in the ‘SaveI’ array and the loaded ‘info. If either the command or the operands are equal.

maximum number of commands that can be displayed on the screen at once leaving room for some sort of navigation instructions. where ’XX’ is the value of the ‘correct’ variable and ‘YY’ is the value of the ‘total’ variable. 88 . Figure 41: Page Separation Marking Example Once all user commands have been compared the results are displayed on the screen in the form ‘You Scored XX/YY’. At the bottom of the screen the user is presented with the navigation option “Draw ->” which when pressed outputs the entered commands to the screen. ‘NEXT ->’ is printed to the display and the ‘waitForKey’ function is invoked. An example of this interface is displayed in figure 41. If these conditions are satisfied. The final results page is shown in figure 42.

The 89 . The current loop stores the current element of the two arrays and this allows several ‘REPEAT’ commands to be nested. The ‘startRepeat’ integer array stores the index number of the first command after the ‘REPEAT’ command is called so that when the list of commands repeat. the starting command is known.Figure 42: Final Marking Routine Results Screen 9.6.3 The Drawing Routine The ‘Draw’ navigation option allows the user to output the commands that they have entered to the display. The ‘repeatCout’ variable is set to the ‘REPEAT’ command operand and this variable is decremented each time the ‘ENDREPEAT’ command is reached. The commands are displayed by looping through each command entered and sending the command and its operands to the ‘interp’ function. The ‘repeatCount’ array simply stores the number of times the command list should be executed.4. There are three variables used within this interpreter loop which are used for logical operations when the ‘REPEAT’ command is called. These commands and operands are obtained from the ‘Save’ and ‘SaveI’ arrays respectively.

6. The first line that is written to the file is the users mark by printing the values of the ‘correct’ and ‘total’ variables. a ‘Continue->’ navigation command is displayed on the bottom right of the screen and the ‘waitForKey’ function is called. Once all commands have been drawn to the display. The system then loops through each one of the elements in the ‘Save’ and ‘SaveI’ arrays and writes their values to the file. 9. If no is selected then the save routine. which is automatically called if the user has received full marks. The save routine displays ‘SAVING. PLEASE WAIT’ on the display and sets the tricolour LED to blue to indicate system activity.4 The Save Routine Once the drawing function is complete. is executed. If yes is selected the system returns to the beginning of the ‘task’ routine. 90 .txt’.‘ENDREPEAT’ command also resets the iteration number of the loop back to the index stored in the ‘startRepeat’ variable and this allows the repeat logic to function. if the user has not achieved 100% in the test a prompt is displayed to ask if the user would like to try again. Using the file system access functions described in detail in the ‘FileLoad’ function definition the ‘fopen’ command is called on a file with operands ‘/local/SAVE.4. An example of the final text output is shown in figure 43. The first operand describes the path to the file to be written to and the second operand tells the system that the file is accessed for write only operations.

The number of commands that can be entered is set by the ‘Cmax’ variable and the command entry can be terminated at any time by pressing the return key. The text ‘WORK SAVED. Figure 44: Free Mode Operation Example 91 .Figure 43: Text File Output Format Once all commands have been written to the file the ‘fclose’ function is called and the tri-colour LCD is set to red to indicate that the system has finished all operations. The code is identical to the ‘Task’ function for the data input routines but does not have the saving or marking routines included.4. 9.7 The Free Function The free function allows users to enter commands that are not compared to the set exercise but are simply executed to allow the user to create their own ideas and experiment with the different LOGO functions of the device. THANK YOU’ is then displayed on screen to indicate the exercise is complete.

allowing the user to start using the exercise mode of the device. The main function is executed automatically when the device starts other system functions and routines can be called from within this function.read()’ function is invoked and the value returned is evaluated. The ‘pad.8 The Main Program Form: int main(). the function simply calls the ‘LoadFile’ function and then the ‘TaskFunction’. If the right key is selected. and asks them to enter either task mode or free mode using the left and right keys on the keypad. 92 . If the left key is returned. This function prompts the user with the name of the device.9.4. the device calls the ‘FreeFunction’ and the user is able to use the free mode of the device as ‘ENTER COMMANDS’ is printed to the display and the ‘FreeFunction’ is called.

The user interface allows the teacher to set an exercise using the commands available in the top right quadrant of the interface and then write the exercise to the device. The interface 93 .net which can be run on Windows XP/Vista/7. but the program source code is included in appendix 13.9.5 PC Software Figure 45: PC Software Interface The details of the PC interface code will not be discussed in this report as the focus is on the hardware device. Figure 44 shows the final PC user interface written in Visual C#.5.

25 £20. and edit an exercise on the device.75 ex Personal Time) Table 14: Project Cost Analysis 94 .00 £22. In order to demonstrate and test the device.also allows the teacher to connect to the device and download the pupil’s marks and attempt to the PC.50 £1. Item MBED Microcontroller Nokia LCD Display Speaker 4x4 Matrix Keypad Technician Time @ £20/Hr.org/users/adamc/notebook/logo-teaching-device-v2/ shows footage of each device feature and PC feature being tested as well as a number of examples of potential student projects.75 (82. 10. This testing process shows that each of the required LOGO functions has been implemented and produces the desired results. a short video located on the mbed community website http://mbed.00 £0. Cost £39. Personal Time @ £15/Hr.00 £1500 (100 units) Project Total: £1782.0 Conclusion & Costing The costing calculations for this project were considered and are displayed in table 14.0 Device Testing A majority of the devices testing was performed during the software design process and any problems were identified and worked around at the time. 11.

along with the hardware drivers created. I feel that the university will benefit from its investment in this project as the potential for development of this project gives it the scope to be passed to other engineers during their third year. The online compiler used for the development of the software is completely free and this is a welcome change to a number of other microprocessors which require compilers and development environments that can cost thousands of pounds. The extent to which these objectives were achieved will be discussed in the subsequent text. In the introduction section of this report was a list of the objectives that needed to be achieved in order for this project to be deemed a success. The LCD displays are manufactured in huge quantities. to teach a cutting edge embedded programming course that is much sought after in industry today. The peripheral hardware was also reasonably priced with their total cost being mainly attributed to the LCD display.Table 14 shows that the total cost of purchased hardware was only £82. There is also the potential for this low cost microcontroller to be used by the university. “ 95 . “The device must be robust and portable in order to be supplied to children to take home for completing homework assignments. and bulk purchases can lower the screen price to around £7.50 (34% saving). the ARM engineers.75 and this seems incredibly reasonable for the development of a fully functioning programmable system. The work on the software drivers have also been of benefit to other users of the mbed microcontroller as the developed library can be made available to users of the device and benefits the other stake holder in this project.

This is no bigger than a modern pocket calculator and more than portable enough for home use.5cm and a height 11cm.xxv “A reasonable number of LOGO commands must be included to allow students to experience a range of programming techniques.The size and robustness of the device has been in constant consideration throughout this project. “ The first revision of the device has all fifteen commands specified in the device specification implemented and working. This means that the device could be running for 3. A prototype using these components could have a width of 6. “The battery life of the device must be of a reasonable length as access to new batteries may be limited. “ Component MBED Microcontroller Speaker Mobile LCD Display Logic Mobile LCD Display Backlight Tri-LEDs Total Current Current Requirement 100mA 10mA 40mA (70mA-30mA for tri-LED) 140mA (10x3)mA=30mA 320mA The total current requirement for the system is 360mA and this can be supplied through the use of two parallel 9V type batteries.1 hours drawing maximum current before the batteries die. The display is deliberately designed to tolerate high levels of shock experienced by mobile phones and the keypad is also made of strong plastic. These commands were deemed the best 96 . The choice of mobile LCD and keypad were both made with size and strength in mind. These batteries would be the best choice as they are able to supply a high voltage with a reasonable battery life of 1000mAh.

each of the specific objectives defined at the start of the project have been achieved. “The manufacturing cost of the device must be kept to a reasonably low level. The device is a usable prototype and is designed to allow future engineers to develop and enhance the existing system. The saved commands also include the number of correct answers compared to the total number of possible answers as the first item in the file. the manufacturing costs of the device are kept low.” As described earlier in this section. “ The device has methods implemented which allow the loading of a set of commands from a binary text file and the saving of entered commands to file with a different name. a PC interface has also been created and allows an easy to use method of staff control. In order for the teacher to create and view results. The function calls and program algorithm logic are key elements in all programming languages and basic mathematical principals and physics principles are also skills the device allows pupils to explore.range of functions to provide an educational introduction to computer programming and allow students to experience manipulating a system to produce images. “The device must allow teachers to upload tasks to the device for the students to complete and practice and be able to download results after a task has been completed. sounds and logical statements. 97 . In conclusion. The total cost for the prototype materials is less than £100 and this would be significantly reduced by bulk component purchase.

The reason that the project remained in this breadboard phase was to allow future development of the device which could lead to a change in peripheral devices that would not fit in the created PCB.12. a set of limited but crucial commands were chosen that were deemed necessary for obtaining a good programming experience.0 Recommendation for Further Work This project was programmed and implemented with future development and enhancement in mind. With more time many more commands could be added and with the replacement of the keypad for a full keyboard. Due to the development time scale involved for this project. One of the major areas in which the project could be improved is by increasing the devices command scope. The device could also be further enhanced by the introduction of hardware addon components. A prototype PCB and casing could also be produced to allow the project to move out of breadboard phase and be tested on children. the number of commands enterable would by almost limitless. 98 . For example a robotic ‘turtle’ could work in tandem with the display to draw the output result to paper. Another idea was to use a motorised etch-a-sketch version of the device to draw shapes and object onto a popular children’s toy.

0 References iLogo programming / Peter Ross.com/support/documents/microcontrollers/pdf/user.php?products_id=569 [Accessed 6th December 2009] xvii 99 .org/nxp/lpc1768/quick-reference/ [Accessed 2nd October 2009] vi LPC1760 USER MANUAL [Online] Available: http://ics.org/nxp/lpc1768/technical-reference/ [Accessed 5th October 2009] viii MBED ONLINE COMPILER [Online] Available:http://mbed.computernostalgia. Addison-Wesley.org/handbook/DigitalIn [Accessed 15th October 2009] x PWM-OUT REFERENCE[Online] Available:http://mbed.htm [Accessed 29th September 2009] v LPC1760 MICROCONTROLLER REFERENCE [Online] Available: http://mbed.lpc17xx.com/SPI_Bus.html [Accessed 5th December 2009] xii PWM COMMAND REFERENCE [Online] Available:http://mbed.org/handbook/SPI [Accessed 12th March 2010] xi SPI INTERFACE TUTORIAL [Online] Available: http://www. National Council for Educational Technology.manual. 1990.2 of the Chiltern LOGO Project.org/compiler/ [Accessed 5th October 2009] ix DIGITAL-IN REFERENCE[Online] Available:http://mbed. London.org/handbook/LocalFileSystem [Accessed 2nd February 2010] xv NOKIA 6100 LCD DISPLAY DRIVER [Online] Available:http://www.cplusplus. Hatfield : Advisory Unit for Computer Based Education.co. Katrina Blythe.org/handbook/PwmOut [Accessed 12th March 2010] xiii FSTREAM FUNCTION DEFINITION [Online] Available: http://www.net/articles/logo.pdf [Accessed 22nd September 2009] iv HISTORY OF LOGO [Online] Available: http://www. iii LOGO COMMAND REFERENCE [Online] Available: http://www.pdf [Accessed 2nd October 2009] vii MBED TECHNICAL REFRERENCE [Online] Available: http://mbed.interfacebus. c1983.alancsmith.com/tutorial/Nokia%206100%20LCD%20Display%20Driver. Children learning LOGO programming: interim report No.15.sparkfun.sparkfun. 1984. iiChildren learning with Logo: a practical guide to working in the classroom.p df [Accessed 5th December 2009] xvi NOKIA LCD 6100 SCREEN [Online] Available:http://www.com/commerce/product_info.com/reference/iostream/fstream/ [Accessed 2nd February 2010] xiv LOCALFILESYSTEM FUNCTION DEFINITION [Online] Available: http://mbed.nxp.uk/logo/LogoCommandRef14b. Blythe.

html [Accessed 14th April 2010] xxv 100 .org/handbook/BusInOut [Accessed 4th December 2009] xix PRINTF FUNCTION REFERENCE [Online] Available:http://www.techlib.cplusplus.com/reference/clibrary/cstdio/printf/ [Accessed 10th December 2009] xx PUTC FUNCTION REFERENCE [Online] Available:http://www.asciitable.cplusplus.com/class/waves/u10l2b.com/reference/batteries.com/ [Accessed 15th February 2010] xxii PROPERTIES OF WAVES [Online] Available: http://www.com/down/S1D15G00_REV1_0.pdf [Accessed 7th December 2009] xviii BUS-IN-OUT CLASS REFERENCE [Online] Available: http://mbed.physicsclassroom.com/reference/clibrary/cstdio/fscanf/ [Accessed 2nd February 2010] xxiv BATTERY CAPACITY [Online] Available: http://www.cfm [Accessed 12th March 2010] xxiii FSCANF FUNCTION REFERENCE [Online] Available: http://www.hantronix.com/reference/clibrary/cstdio/putc/ [Accessed 14th December 2010] xxi ASCII CHARACTER TABLE [Online] Available: http://www.LCD EPSON CONTROLLER DATASHEET [Online] Available: http://www.cplusplus.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.