14
FUZE workshops are sponsored by:

FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

FUZE workshops are sponsored by:

Page 2: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

The FUZE coding environment is very helpful if you ask nicely. Here are a few tips & tricks to get you usingthe editor fluently. First, lets get to know the variouswindows of FUZE.

Use FUZE like a PRO!

When you start FUZE, it will boot into immediate mode. Itwill look like the blue box on the left - this is where ourprograms are run. In immediate mode you can give thecomputer commands and press enter to get immediatefeedback - hence the name!Try typing: print 1832.75 * 2456.84 to see what I mean.

Take a look at the top row of keys on yourkeyboard (F1, F2, F3, etc.). These are calledthe function keys and we use them quitea lot with FUZE.

Press [F2] to open the program editor.This is where we write our programs.Press [F2] again to return to immediatemode.

Take a look at the row of buttons at the topof the editor window. Most are simple - youcan begin a new tab, save, load and close your programs, RUN the code, search for specific text,change the size of your text, and even change the colour scheme of the whole editor.

Use the arrow keys to move the cursor quickly. Try using the shift key in conjunction with the arrowand ctrl keys to highlight sections of your code efficiently. Next, and this one will save you a lot oftime, press home or end on your keyboard to jump to the start or the end of a line respectively.Lastly, PgUp and PgDn can be used to quickly jump from page to page.

SAVE YOUR WORK OFTEN.

When you RUN a program, FUZEautomatically saves your work. The first timeyou RUN a program, FUZE will ask you toSAVE your work as a name.

No matter how careful you are, some thingscan always go wrong, so make sure to saveyour work regularly. With longer programsIt is good practise to SAVE AS [F5] a newname to be safe.

The box on the right shows the desktop. Yours may looka little different but we are concerned with the StartFUZE icon in the top left. Double click to start FUZE!

Page 1

This little flashing line is called the cursor!

Page 3: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Introduction & Contents

Hello! Welcome to FUZE coding.

FUZE makes learning real coding as accessible as possible.

Coding can appear pretty complicated at first. It's full ofstrange words, mathematical concepts and problem solving.Don’t let any of this put you off as, similar to most things,

once you delve a little deeper it’s not as scary as it first looks.There is one thing though… Typing. Lots and lots of typing.

If you want to get to grips with real coding, there's no getting around this. You will be typing countlesslines of code and you will make mistakes. You might spend a fair amount of time having to check for tinyspelling and syntax mistakes. Not to worry - debugging your code is a very important part of the learningprocess. Every mistake you fix makes you a better programmer!

Over the next 10 pages, you will be taken on a journey of understanding from the most simple programimaginable to comfortably using some of the more flashy programming techniques.

When it comes to learning to code, we believe that you start with 3 things: Loops, Variables and If ThenStatements.

If you understand these three things even a little bit, you will begin to understand the most complicatedprograms out there. ALL programming languages rely on these fundamental concepts in some form oranother, so knowing how they work is a vital step in your journey to being a coder. Ready?

Contents:

Project 1: HELLO WORLD - Page 3

Part A: An introduction to the concept of LOOPs,use simple commands to print text on the screen.

Part B: We use colour commands, changing fontsizes and delays to liven up the program!

Project 2: HOW D'YA LIKE THEM APPLES? - P5

Learn about the next fundamental aspect ofprogramming. Use variables to manipulate andkeep track of stored numbers.

Project 3: NEON LIGHTS - Page 6

Part A: You thought you were done with loops?Think again. Wire up an LED to the GPIO board andput your LOOP knowledge to the test.

Part B: We move up to the next level with FORLOOPs. A vital programming concept.

Project 4: LET'S GET QUIZZICAL - P8

An introduction to IF THEN statements and theINPUT command. Use what we know so far tocreate a Quiz game.

Project 5: ANALOG WORLD - P9

Part A: We hook up an analog light sensor and useit to animate a circle on screen.

Part B: Learn about screen coordinates to build acharacter on screen using circles.

Project 6: ARRAY OF HOPE AND FORTUNE -P11

Create your own digital Magic-8 ball and learnabout another key to programming: arrays

Glossary of Commands Used - P12

Quickly reference any troublesome commands inour comprehensive glossary. Covers everycommand used in the booklet.

Page 2

Page 4: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

“Hello World"

Project: 1a

Ready for your first computer program? I hope so!

This sheet contains all the information you’ll need - read it carefully but don’t hesitate to ask for help!

Press [F2] to go to the FUZE editor and enter the code below in the black box:

RUN this with [F3].

IMPORTANT:THE COMPUTER WILL ASK YOU TO SAVE.Please enter your name and hit enter.

Next, change your code to look like thecode in box number 2.

Press [F2] to go back to the FUZE editor.

1. PRINT “Hello World”

Let’s create a LOOP. We want thecomputer to run our program over andover again.

We start with the word LOOP, end withREPEAT and put our instructions in themiddle.

It's a little bit like a sandwich!

When the program executes the REPEATcommand the program returns to theLOOP line.

IMPORTANT: While your computer isbusy with a LOOP you must press [ESC] tostop the program before returning to theeditor. [F2]

RUN the program! [F3]

Next, see how the “ ; ” symbol changesyour program.

The WAIT command tells the computer topause for an amount of time before itcontinues the program. Here we tell it towait for 1 second.

Edit your code and RUN it! [F3]

Hey, look down here! This section of the page will contain challenges as we go ahead.Want to prove your skills? See if you can beat the HACKER CHALLENGE!

HACKER CHALLENGE: Can you make your program RUN Ten times faster?

1. LOOP

2. PRINT “Hello World “

3. REPEAT

1. LOOP

2. PRINT “Hello World “;

3. REPEAT

1. LOOP

2. PRINT “Hello World “;

3. WAIT ( 1 )

4. REPEAT

IMPORTANT: You are not ADDING each section to yourcode. CHANGE your code so that it looks like the code ineach box. Follow the steps carefully.

You should write about anything you like! It doesn't have tosay "Hello World" - It is your program after all!

Page 3

Page 5: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

“It's a beautiful World”

Project: 1b

These new commands will add somecolour to our program.

INK = changes the colour of the text.PAPER = changes the colour of thebackground. Try your favourite colours!

RUN the program! [F3]

1. LOOP2. INK = BLACK3. PAPER = RASPBERRY4. PRINT “Hello World ”;5. REPEAT

CLS clears the screen when you run theprogram - this means it will start a freshpage every time.

This last command is lots of fun.

FONTSIZE allows us to make the textbigger and smaller. The number in thebrackets tells the computer which size tomake it.

The minimum is ( 1 ) and the maximumis ( 20 ).

Experiment with different sizes to makeyour program look interesting.

Add the command to your code thenRUN the program. [F3]

1. CLS2. LOOP3. FONTSIZE ( 5 )4. INK = 195. PAPER = 276. PRINT “Hello World ”;7. WAIT ( 1 )8. REPEAT

The FUZE knows the name of30 colours - they are saved inmemory as numbers.

Try using numbers instead ofcolour names - put yourself inthe computer’s shoes!

HACKER CHALLENGE: Can you add another line of text in differentcolours? You must think carefully about the order of your code to get thisright. Use whichever colours you like, and PRINT something new.

Try INK = RANDOM( 30 ) for random colours!How would we achieve random Fontsize? Be warned of tricky brackets!

Welcome back! Let’s keep going. Remember: [F2] returns to the editor, and [F3] runs the program.

This page is going to make our project a little more interesting to look at! Let’s get started:

Page 4

Page 6: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Project: 2“How d'ya like them APPLES?”

Variables are extremely important tools for programming. In fact, variables are essential to create everysingle one of the applications and games which you play and enjoy. We use variables in everything fromboring databases to video game controllers, and here's how they work.

A variable is a label we give to a location in the computer’s memory. A variable can change, and we cancontrol what happens to them. Below, we are going to use simple variables to help us organise a class.

In Immediate Mode (see page 1), type in the commandsdisplayed to the left. After each command press the ENTER key.

The words ‘girls’, ‘boys’ and ‘class’ are our variables. We coulduse anything but it’s best to use appropriate words so yourprogram is easy to understand.

girls = 15

boys = 15

class = girls + boys

PRINT class

1. CLS2. apples = 103. LOOP4. CLS5. INK = GREEN6. PAPER = BLACK7. PRINT "I have "; apples ; " Apples. "8. WAIT ( 0.5 )9. PRINT "If we eat one... then..."10. apples = apples - 111. WAIT ( 1 )12. REPEAT UNTIL apples = 013. CLS14. PRINT "I have no Apples… And a tummy ache…"15. END

Press [F2] to open the editor andenter the program on the left.

Use your own colours!

First, we define our applesvariable with a value of 10.

To subtract 1 from this variable,we use the line: apples = apples -1

There is one more new trick here:

REPEAT UNTIL tells the program tostop repeating when a condition ismet. Here, we are telling it to stopwhen our apples variable reaches0. The computer then moves on tothe lines beneath.

Now we’re going to write a simple program that uses variables. Pay attention to the syntax of line 7.When we PRINT the apples variable, we are printing the value stored, not the word.

HACKER CHALLENGE:1. Can you make your program eat 2 apples at once?2. Can you write a new program that does the opposite? Instead of eating the apples until we have none, perhaps it couldgive us apples until we have ten.

Page 5

A good way of thinking about this is that you are storing something in a boxand giving the box a label.Let's say we create a variable called apples and want to store the number 10.We must first define our variable with the statement: apples = 10This creates a memory location called apples which now holds our number!

This is just apicture!

There is not awooden crateinside thecomputer!

But you knewthat..

Page 7: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

1. PINMODE ( 6, 1 )2. PINMODE ( 7, 1 )3. LOOP4. DIGITALWRITE ( 7, 1 )5. DIGITALWRITE ( 6, 1 )6. WAIT ( 0.5 )7. DIGITALWRITE ( 7, 0 )8. DIGITALWRITE ( 6, 0 )9. WAIT ( 0.5 )10. REPEAT

“Neon Lights”

Project: 3a

Time for some electronics. In this project we are going to wire up an LED to our input/output (I/O)board. Follow the instructions below very carefully to make the circuit.

We need to add an LED to the breadboard. Unlike the one displayed to theright, the FUZE breadboard is black. It sits comfortably at the top of the unit.

Pick an LED from the component box and connect it as illustrated here:

NOTE: the LED has one slightly longer leg. This should be at the top.

The red wire connects from GPIO pin 7 to the top pin of the LED (E4).

The blue wire is connected from the GND (ground) pin to the firstavailable hole along the blue line. The short LED leg goes next to the bluewire.

Press [F2] to go to the editor,write the code on the left andRUN the Program [F3]

1. PINMODE ( 7, 1 )

2. DIGITALWRITE ( 7, 1 )

Remember the LOOP command from the first sheet? We’regoing to use that again here to make our light flash! We have touse the wait command otherwise the flash will be too fast.

Type in the code to the left then RUN the program! [F3]

How could you make the LED flash faster or slower?

1. PINMODE ( 7, 1 )2. LOOP3. DIGITALWRITE ( 7, 1 )4. WAIT( 0.5 )5. DIGITALWRITE ( 7, 0 )6. WAIT ( 0.5 )7. REPEAT

PINMODE (7, 1) tells the computer that GPIO pin 7 is set to mode 1 (output).

DIGITALWRITE (7, 1) sends an on signal (1) to pin 7.

A B

C D

EA

B C

D E

1 2 3 4 5 6 7 8 9 10 11

1 2 3 4 5 6 7 8 9 10 11

A B

C D

EA

B C

D E

1 2 3 4 5 6 7 8 9 10 11

1 2 3 4 5 6 7 8 9 10 11

On the right we have written the code to flashtwo LEDs within your loop. First you will needto connect another LED and wires to the GPIOand breadboard. Then add the new lines toyour program.

HACKER CHALLENGE:

Can you change your code so that your LEDsflash alternately (when one is on the other isoff)?

Top leg (longer)

Bottom leg (shorter)

Turn off the electrical current to the LED by sending pin 7 an off signal (0) using DIGITALWRITE:

2. DIGITALWRITE (7, 0)

Since the PINMODE line only sets up a pin for output, we do not need to change it to turn the light off.

Page 6

Page 8: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Project: 3b“FOR the love of LOOPS”

Add more LEDs so you have eight in total.

You can use any colours from the component box.

Remember the longer of the two LED pins must bein the top section. Be sure that each of the redwires is matched correctly.

Go to the editor [F2] and click NEW to open a newprogram tab.

Notice we have indented the commands that arewithin a LOOP or FOR LOOP. This just makes itmuch easier to read our code. Use the TAB key toindent a line.

Enter the code on the left and RUN [F3]

Let’s go over the new function we are using.

The first three lines of our code begin a clever LOOPthat lets us save some time. Normally we wouldhave to write each PINMODE separately:

PINMODE ( 1, 1 )PINMODE ( 2, 1 )PINMODE ( 3, 1 )

Instead, the variable called pin will cycle throughthe numbers 0 to 7 and set the PINMODE for each.

FOR pin = 0 TO 7 LOOPPINMODE ( pin, 1 )

REPEAT

The FOR command initiates a LOOP. In this case, itcounts from 0 to 7 increasing by one each time itREPEATs.

When pin = 7 the LOOP will stop, and the programcontinues.

So, to sum up: We have three loops in total. Thefirst one, a FOR LOOP, sets our pins to Outputmode. We then have an infinite regular LOOPsurrounding another FOR LOOP, which usesDIGITALWRITE to send an on (1) signal to the GPIOpin specified by the ‘pin’ variable. It then waits for0.3 seconds then sends an off (0) signal to the samepin. Remember - there is an infinite LOOP here soyou must press the [ESC] key to end it!

FOR pin = 7 TO 0 STEP -1 LOOP

1. FOR pin = 0 TO 7 LOOP2. PINMODE ( pin, 1 )3. REPEAT4. LOOP5. FOR pin = 0 TO 7 LOOP6. DIGITALWRITE ( pin, 1 )7. WAIT ( 0.3 )8. DIGITALWRITE ( pin, 0 )9. WAIT ( 0.3 )10. REPEAT11. REPEAT

HACKER CHALLENGE:

FOR LOOPs are really useful due to their versatility.

Our LOOP counts from 0 to 7, one at a time. What if wantedto count backwards, from 7 to 0?

The line above shows us how to do exactly that. We arecounting from 7 to 0 in steps of -1 each time.

We can also use “STEP 2” to count up in twos, “STEP -2” tocount down in twos, or “STEP 3” for threes etc.

Can you add a second FOR LOOP to count backwards, sothat your flashing lights sequence begins in one directionthen does the reverse?

Notice the blue words in our programs. These are our variables. We're going to use variables to create aclever LOOP. The value stored in the variable will change. Hence the name!

Page 7

Page 9: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

We’re going to make an awesome quiz game using everything you’ve learned so far, along with a newcommand (INPUT) and a brand new concept: IF THEN statements

Press [F2] to go to the editor to enter the short program below. The line: IF age > 25 THEN checks to seeIF the value stored in the age variable is greater than ( > ) 25. IF it is, THEN we get a message!

1. PRINT "Hello, how old are you? "2. INPUT age3. IF age > 25 THEN4. PRINT “Wow.. “; age ;“! a living fossil! “5. ENDIF

1. score = 02. CLS3. PRINT "Hello and welcome to the quiz. "4. WAIT ( 2 )5. PRINT "Please answer in lower case. "6. WAIT ( 2 )7. INK = YELLOW8. PRINT "Q1. Which elemental type is Pikachu? "9. INPUT answer$10. IF answer$ = "electric" THEN11. PRINT "Correct! Pikachu is an electric type! "12. score = score + 113. WAIT ( 2 )14. ELSE15. PRINT "Incorrect! "16. WAIT ( 2 )17. ENDIF

IMPORTANT: IF AND THEN

An IF THEN statement tells thecomputer to do something only ifa condition is met.

Since we are saving the player’sanswer as answer$, we must usethe same variable name in the IFTHEN statements.

It is very important to make sureyour spelling is correct!

RUN [F3] your program and see ifit all works!

You might notice the INPUT command above - it's a nice and simple command, we just use it to allow theuser to type something in. We save what they type in as a variable. We can then check the contents ofthe variable in our IF THEN statement.

Click NEW to open a new program tab and look at the code below. Here we have a very small quiz. Itbegins with a small introduction and only has one question. Copy out the code below, but REMEMBER:your quiz should be about whatever you want. Invent your own questions.

IMPORTANT: Remember, we are checking to see if the player's answer is exactly equal to the correctanswer, including capital letters!

IMPORTANT:

For every IF THEN statement weuse, we must put an ENDIF atthe end.

HACKER CHALLENGE:1. Add questions to your quiz until you have at least 5.

2. Using the OR command, can you create a question which has multiple correct answers?IF answer$ = "answer" OR answer$ = "answer2" THEN

3. Can you display the player score at the end of the quiz?

“Let's get Quizzical”

Project: 4

Page 8

Page 10: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

“Analog World"

We’re going to use a very simple electronic component called a Light Dependant Resistor or LDR for short.It limits the amount of electric current (the name given to flowing electricity) that goes through a circuitdepending on how much light it is exposed to, and gives the computer a number to represent this.

Grab an LDR (Light Dependent Resistor - see pic) and wire up tothe breadboard as displayed.We send current into the LDR using the red wire. The LDRresists an amount of this electricity,and sends the rest along the blue wire.We read the current coming back outof that blue wire using the command:ANALOGREAD ( 0 )0 because we use analog pin 0!

Press [F2] to open the editor and enter the program below.

an LDR

1. CLS2. LOOP3. radius = ANALOGREAD ( 0 )4. COLOUR = RANDOM ( 30 )5. CIRCLE ( MOUSEX, MOUSEY, radius * 3, 0 )6. UPDATE7. REPEAT

HACKER CHALLENGE:1. Could you put another circle on the screen, also controlled by the mouse, but in a different place on screen? There shouldbe TWO circles on screen. Change the colour of the second circle too!

1. LOOP2. CLS23. radius = ANALOGREAD ( 0 )4. COLOUR = RASPBERRY5. CIRCLE (GWIDTH/2, GHEIGHT/2, radius * 3 ,1)6. UPDATE7. REPEAT

You might be wondering what GWIDTH/2 and GHEIGHT/2 mean! The computer stores various informationin special variables called system variables. These particular ones store the width and height of the screenin pixels. We divide these numbers by 2 to put the centre of our circle right in the middle of any display.

Next we're going to change things a bit below! But first, some explanation.To keep track of the mouse pointer, the computer holds 2 changing numbers in system variables to recordthe X (MOUSEX) and Y (MOUSEY) position of your mouse on screen. We use MOUSEX and MOUSEY toplace the centre of the circle on the mouse coordinates.Remove the CLS2 command from our LOOP then, finally, make the circle hollow with a 0 at the end of theCIRCLE line.

Press [F3] to RUN your code!

Wave your hand over the LDR to changethe size of the circle!

If your circle is a bit on the small side, tryincreasing the 3 in radius * 3, since this ismodifying the size of our circle bymultiplying the radius variable.

Project: 5

Page 9

Page 11: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Project: 5b“Bear With Me"

Add a second LDR as shown on the left. Thesecond blue wire goes from the top of the LDRto analog pin 1.

It is best to have a bit of distance between thetwo LDRs so place them as far apart as youcan. However, notice that the red and bluelines have a break in them halfway along sostay on the left of this.

Now we can read two LDRs individually.

Start a fresh program, enter the code as shown above then RUN with [F3]

We start by setting full screen mode to on before starting the main program LOOP. Our first command isCLS2, which we must use for animation loops. Following that, we define two simple x and y variables tostore our desired starting position. Next up, we set a couple of helpful variables to store the valuescoming into ANALOGREAD (0) and ANALOGREAD (1)

Next we draw a sequence of circles in the centre of the screen and use the radius variable to positioneyes to the left ( x - radius ) and right ( x + radius ) of the centre of the screen. We do the same for theheight ( y + radius ). Finally, two more circles are drawn to be the pupils.

1. FULLSCREEN = 12. LOOP3. CLS24. x = GWIDTH / 25. y = GHEIGHT / 26. radius = ANALOGREAD( 0 )7. eyeradius = ANALOGREAD( 1 )8. COLOUR = PINK9. CIRCLE ( x, y, radius * 3, 1 )10. COLOUR = WHITE11. CIRCLE ( x - radius , y + radius / 2, eyeradius, 1 )12. CIRCLE ( x + radius , y + radius / 2, eyeradius, 1 )13. COLOUR = OLIVE14. CIRCLE ( x - radius , y + radius / 2, eyeradius / 3, 1 )15. CIRCLE ( x + radius , y + radius / 2, eyeradius / 3, 1 )16. UPDATE17. REPEAT

HACKER CHALLENGE:Could you give the bear ears and a mouth? You'll need a few more CIRCLE lines.You could try making an oval using the ELLIPSE ( x, y, width, height, fill ) command for the mouth - maybeone on top of another?Create your own animal using circles and ovals, make it as silly as possible!

Page 10

Page 12: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

“Array of hope and fortune”

Project: 6

So, we've covered three of the most important aspects of programming. LOOPs, variables and IF THENStatements. Now… let's take it a step further and talk about arrays.

We can store a single value in a variable, as you know. What if we wanted to store multiple values in oneplace? If we wanted to store the 7 days of the week, for instance. A rather terrible and long-winded wayof doing this would be to define 7 separate variables:

day1$ = "Monday"day2$ = "Tuesday"day3$ = "Wednesday"

To do this efficiently we'll need a table of variables. These are referred to as arrays.

We use arrays to create a list of values. We might use this to create something a bit boring like a classregister or a calendar. We on the other hand are going to create an awesome virtual Magic 8 Ball.

First, we need to give our 8-Ball a number of responses to the questions we will ask:

1. DIM answer$( 4 )2. answer$( 0 ) = "You're in luck!"3. answer$( 1 ) = "It's not looking good…"4. answer$( 2 ) = "Almost certainly."5. answer$( 3 ) = "Not today…"6. answer$( 4 ) = "Maybe!"

Our first task is to create the emptytable.

DIM answer$ ( 4 )

This line creates an array of 5 values(remember - we start from 0).

We then create statements to defineeach location in the array.

HACKER CHALLENGE:1. Add at least 3 more answers to our 8-Ball array for a grand total of 8. Make sure it works!

7. FONTSIZE( 3 )8. LOOP9. CLS10. PRINT "Spin the ball… Ask me any question! "11. INPUT question$12. num = RND( 5 )13. PRINT answer$( num )14. PRINT "Let's play again! "15. WAIT( 3 )16. REPEAT

We can also check if our array is working. Run the program with [F3], hit [ESC], then whilst in immediatemode, type: PRINT answer$ ( 1 ) and hit enter. If "It's not looking good…" is displayed, we're all good!

Now we just need to create aprogram to access our array!

We use INPUT to allow a player totype a question for the 8-Ball.

We then define a variable callednum as a random numberbetween 0 and 4. Remember, 0-4is 5 values total.

We use this variable to access andPRINT an answer from a randomlocation in our array.

Simple as that!

Page 11

Page 13: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Glossary

Glossary of Commands Used

CLSCLS means Clear Screen. This command clearsthe screen buffer, and also issues an UPDATEcommand to update the visible screen with thecontents of the screen buffer.

CLS2 / UPDATECLS2 clears the screen buffer, but does notautomatically issue an update command.

UPDATE is used to manually update the visiblescreen with the contents of the screen bufferwhen desired in the program.

DIMDIM initialises a multidimensional variablearray. Any number of dimensions can be used,so DIM A( 10 ), DIM A( 10, 5 ) and DIM A( 10, 5,5 ) are all valid. Arrays, or lists, are used to storemultiple values in a single variable which can beaccessed by its index.

DIGITALWRITEWrites a digital signal to a specified GPIO pin.DIGITALWRITE(pin, 1) sends an on signal.DIGITALWRITE(pin, 0) sends an off signal.

ENDEND stops the program running and returns toimmediate mode.

ENDIFPlaced at the end of an IF statement, ENDIFmarks the end of the conditional action(s).

FONTSIZESets the size of the font for subsequentlydisplayed text.

FONTSIZE(x) where x may range from 1 to 20.

FOR LOOPInitialises a loop to repeat a specified amount oftimes. For example:

FOR counter = 0 TO 100 LOOPPRINT "I am at number "; counter

REPEAT

The above loop counts from 0 to 100 then moveson past the repeat command.

IF / THEN / ELSECreates a conditional statement which allowssubsequent lines to be executed provided thecondition is met. ELSE allows for an alternativecondition should the original condition not bemet.

INK & PAPERAllows the user to set the text and backgroundcolour.

INPUTAllows for a user to enter information using thekeyboard. Requires a variable name in order tosave the inputted text.INPUT name$

LOOP / REPEAT / UNTILInitiates a series of instructions to be executedrepeatedly. The loop begins with the LOOPcommand, and ends with the REPEAT command.UNTIL allows an ending condition to be specifiedwithin a loop.

PINMODESets a GPIO pin to be ready to output/inputelectricity. PINMODE(pin, 1) sets to output,PINMODE (pin, 0) sets to input.

WAITInstructs the computer to do nothing for aspecified time.

WAIT ( 1 ) waits for 1 second.

Page 12

Page 14: FUZE workshops are sponsored by · 2017-12-14 · Introduction & Contents Hello! Welcome to FUZE coding. FUZE makes learning real coding as accessible as possible. Coding can appear

Published in the United Kingdom ©2017 FUZE Technologies Ltd. FUZE,FUZE BASIC, FUZE logos and associated designs, documentation and

materials are ©FUZE Technologies Ltd.FUZE registered trademark #UK00002655290

Illustrations by Ursula Hart

No part of this document may be copied, reproduced and ordistributed without written consent from FUZE Technologies Ltd. TheArduino brand, Arduino logo and their designs are copyright ArduinoLLC. Intel and their respective logos are Copyright ©Intel Corporation.

ASUS and their respective logos are ©ASUSTeK Computer Inc.All rights reserved.

FUZE is developed in the UK by:

FUZE Technologies Ltd.15 Clearfields Farm

Wotton UnderwoodAylesbury,

BuckinghamshireHP18 0RS

England

Contact informationemail: [email protected]

phone: +44(0) 1844 239 432