Flowcharts for Picaxe BASIC Tech Studies Page 1 of 11
In the college you will use the PICAXE Programming Environment in order to carry out all of your program writing, simulating and downloading to the target processor. If you want to get ahead of the game then you can, quite legally there are no restrictions on the software use this same software at home. In order to download the software you can either type the following in to your web browser http://hame.uk.com/jwc/html/syscontrol.html or you can use your phone to take you to the web-page by scanning the QR code on the right >>> Download and install as for any other piece of software. Page 2 of 11
Start up the PICAXE Programming environment by double clicking on the icon on your desktop >> When the program starts select the following PICAXE mode PICAXE-28X2/40X2 from the drop down list. This should take you to the start-up setting as shown below. This is the default program editing page. Where you will type in / write all of your PICAXE programs. There is a second environment available to us for programming and we will start it up now:- Page 3 of 11
Before we start the program let s take a look at what a flowchart is. A flowchart is a form of graphical programming. It allows us to identify the correct program sequence and further it helps sort out the logic of the program. Every flowchart begins with a element and has many other elements in between. element and usually, but does not always end with a Some of the elements you will use when writing your flowcharts are as follows:- Inputs and Outputs Processes Decisions All elements are joined by directional lines or There are other elements but these are the main elements that we will use to start with others will be added as we progress. Here is a simple flowchart:- program start do something make a decision [loop back] program terminate Let s take a closer look at how we can draw up flowcharts for all of the programs we have met so far. Page 4 of 11
Examine the tool-bar at the top of the screen and click on the flowchart button. This will open a new programming editor environment. This programming environment is for a graphical programming language called Flow Charting. First I will try and explain all of the graphical symbols. The default toolbar is shown below split into each button. Select Zoom area Pan Add connection points Output commands If commands Sub commands Select within area Zoom in or out Draw lines Add label movement Delay commands Other commands Page 5 of 11
Each button that you select from the main toolbar will bring up another toolbar that expands available graphical commands. Let s look at the first example program from your hand-out Example-1. The next flowchart is a bit more complex. It has a decision making process in it. You may have noticed that each element of a flowchart has only one input and one output the only element that has more than two is the decision element this has three an input and two outputs. The ouputs are the result of a question and can be either true or false, good or bad or just yes or no. As an example let us imagine that you are writing a program that will do one thing if the input pinc.0 = 0 and will do an other thing if the input pinc.0 = 1. We can represent this in code as: At the if statement just ask the question, is pinc.0 = 0 if the answer is NO then follow the N route out of the decision element otherwise follow the Y route. Simple, yes? Earlier in the text I said that we can sort out LOGIC using flowcharts, if you find that there is more than just a yes or no answer at a decision element then you must have more than one question at this point therefore you re-think your question and re-draw your flowchart. Page 6 of 11
Page 7 of 11
So how do we go about building a flowchart? Let s look at the Example1 program and construct the flowchart shown at the top of page 6. Open a new programming editor environment and select the flowchart button. The people at PICAXE have started your flowchart for you by placing the start element on the page for you:- Perhaps now is a good time to save your first flowchart. Click on File and select save as >> When the dialogue box opens up type in Example1 and click OK remember, save your programs often too many times I hear the cry go up that someone has lost the program that they have been working on because a computer has failed or frozen. This is not the computer s fault, if you have been working on a program for say 5 minutes then stop and save it, if you decide that you want to run a simulation then stop and save before you do it or if you decide you want to download your latest masterpiece to the target microprocessor then stop and save your file before you do it you have been warned. Some people get quite offended and annoyed when I laugh at them when they lose their work just let me say, if you feel that you may be one of these people THEN SAVE YOUR WORK FREQUENTLY SAVE, SAVE, SAVE YOUR WORK- YOU HAVE BEEN WARNED. Examine the first line of program code This is an output the program is saying set the output pin 7 HIGH Look at the button-bar and select the OUT button This will open another button bar Examine the options Page 8 of 11
The HIGH option is pre-selected and you can click anywhere on the yellow area to drop the HIGH element on the page But I suggest you position it one or two dots below the START element. You should now have something similar to that shown on the right When we insert the HIGH element the default is 0, but we want HIGH = 7. No problem click on the arrow at the left of the button bar. Click on the HIGH element look down at the bottom left of the editing area und you should see an input box like this >> Click on the small arrow on the right of the box and select the value 7 from the drop-down list >> Many of the options that we have to change use this same process. Click on the curly arrow to go back to the main toolbar We will now join these elements together using the lines element click on it now Notice now that as you move the cursor about the line terminators on the elements change to a bubble outlined in red this indicates that a line can either start or end at this point >> Make sure the bubble shows on the START termination CLICK on it and drag towards the HIGH element it can be difficult to position the arrow at the correct point but a bit of practice helps. If you end up with a line that you feel is incorrect the just place the cursor over it and click it should disappear, sometimes when the termination points are close together then drawing the line upwards makes the arrow snap to the required point >> Examine the next line of program code We now need to insert a DELAY element >> This brings up another button bar: Again examine the options We want to PAUSE the program therefore we will select >> Again drop the element a couple of dots below the previous element >> Now as before select the arrow on the left of the button-bar, select the element then at the bottom of the screen change the default value of 1000 to the required 2000. Watch out if you hit the delete key the program will think you are deleting the element just click on NO and you should be ok. Now go back to the main button-bar and join the elements. Page 9 of 11
Your flowchart should now look like this >> You might want to expand the editing area to fill the available screen space do this by clicking on the MAXIMISE button at the top right of the editing area. OK repeat this until you are down to PAUSE 3000 >> In order to get everything visible on the screen you may have to ZOOM out. This program employs a strange method for this. Select the ZOOM IN OUT button >> Other than the cursor changing to a magnifying glass with a + and next to it nothing else seems to happen. If you click with the left mouse button and move the cursor UP and DOWN then the zooming will take place. OK things could end up so small that they are unreadable if we keep building our flowchart downwards. In order to prevent this we can continue our construction on the right hand side of the current program [never on the left] and join the bottom of the left most program with the top of the right >> Now complete the flowchart for Example1 Page 10 of 11
Just a question HOW MANY TIMES DID YOU SAVE YOUR WORK? Get used to saving your work if you don t you may well regret it. Now take a look at the hand-out which contains the programming examples and see if you can create flowcharts for the given programs. Page 11 of 11