Hardware Reference
In-Depth Information
prints out some simple user instructions about the keys. Basically there are a group of keys
that will change the colour of the drawing track, a key to wipe the screen in case you have not
got a tilt switch itted, some keys that control what is drawn and inally two keys to save the
images and post them to Flickr - and hence to Facebook.
he main function after the instructions are printed out is a simple endless loop of reading
the encoders and then drawing the lines when that function returns with an updated read-
ing. he readEncoders function is basically what is in Listing 15-2 only for two encoders.
It keeps looking at the input port and makes the decisions based on what it sees. his func-
tion can do this for both encoders by using a for loop and shifting the reading for the X
encoder into the least two signiicant bits and then shifting the Y encoder into the least sig-
niicant bit for the second trip through the loop. When a movement is detected the logic
variable move is set to true and the function returns to do the plotting on the screen. he tilt
switch is also monitored, and the screen is wiped if it is found to be upside down. he incre-
ment value is set at 8; that is, it moves 8 screen pixels per click, but you can make it a smaller
value if you want iner control over the movement of the plotting point. When this function
returns, the values in the current reading list have been updated, and the program draws a
line between the current point and the last point. he current point is replaced with a grey
square to allow you to see where you are, in the same way that mechanical versions of this
program had a current point that you could just see. his allows you, in theory at least, to
retrace over a line to start of somewhere new. So before the program draws a line this cursor
square has to be erased and put back in the new position after the line is drawn. hat is why
there are three drawing commands where you might be expecting only one. he current read-
ings are copied into last-reading variables before the screen is updated.
he checkForQuit function looks at not only quit events but also key events. hese drive
the settings of the program. For example, the current drawing colour can be changed by
pressing a key; all the primary and secondary colours are available as well as black and white.
Note that for black you have to press the K key because the B key is already taken with
switching to blue. he spacebar or Delete key simply calls the blank_screen function.
he later part of the checkForQuit function performs the neat special efects of the pro-
gram. First the L key will draw a line between the current point and a previously saved point.
Next the C key will draw a circle centred on the current point with a radius given by the dis-
tance to the saved point. Finally the S key will save the current point as the set point for
those two previous commands. he circle drawing has to be in a try structure to prevent the
program from crashing when the current point is the same as the saved point. hese circles
and lines give the drawings a lot more interest than the random scribblings that is often
made with these sorts of toys.
he saving and transfer keys are the Home key and the hash key. he Home key saves the
current screen into the roto-sketch folder as a PNG picture ile. When you press this for
Search WWH ::




Custom Search