Hardware Reference
In-Depth Information
he checkStep function irst looks at the variable that deines where the trigger to the next
step is coming from. If this is from the internal timer, the time now is compared to when the
next step should occur, and if it is time, the updateSeq function is called, and the step
variable is incremented and tested to see if it has not gone over the maximum number of
steps. If it has then the step variable is reset to zero. his is known as wrapping around the
counter. Finally the time for the next change is set up by adding the time now to the time
increment variable. If the system is set up so that the sequence is advanced on a hardware
input then that input is looked at to see if it is diferent from last time. his indicates a level
change or an edge has been detected, and if the input level is now high, it is time to advance
the sequence in the same way as before. One line that might puzzle beginners is this:
switchState = pfio.read_input() & 1
What the & operator does is to perform a bitwise AND operation between what is read and the
number 1. he result of this is that the variable switchState just contains the least signii-
cant bit of the byte that is read from the PiFace board's input lines. his means you can
advance the sequence from the lowest switch or the music by attaching the special beat fol-
lowing circuit to it. I will describe that circuit later in this chapter.
he updateSeq function basically does two jobs; irst it updates the position of the sequence
indicator square by drawing a long thin rectangle in the background colour to erase the old
square, and then drawing a new one. Finally it outputs the next pattern in the sequence with
the following line:
pfio.write_output(seq[n])
his takes the list called seq and extracts the value that is next in the list given by the vari-
able in the square braces and then writes it out to the PiFace board. his single line is what
actually does the turning on and of of the lights; everything else just supports this one line.
he setUpScreen function simply calls other functions that draw the basic framework of
the screen. So after wiping out everything in the screen bufer and setting it to the back-
ground colour there are ive calls to draw control boxes. his call takes the parameters of the
words in the box, its location in the x axis and the width of the box. Finally the drawCol , or
draw column, function is called in a loop 32 times, one for each step in the sequencer. he
two parameters it takes is what step in the sequence it is and what bit pattern it is to set it at.
Drawing text under the pygame module is a bit complex. First you have to deine your font,
which was done at the start of the code; the None parameter is the name of the default font ile,
and the number used is the font size. You then have to render the font into a bitmap, which is
a little bit of a screen bufer that contains only the font characters you want. You then deine a
Search WWH ::




Custom Search