Raspberry Pi Hardware Projects 1 by Andrew Robinson

Raspberry Pi Hardware Projects 1 by Andrew Robinson

Author:Andrew Robinson [Robinson, Andrew]
Language: eng
Format: epub, pdf
Tags: Computers, Systems Architecture, General, vl-nfcompvg
ISBN: 9781118588949
Google: hgwFAQAAQBAJ
Amazon: B00FGRLM9U
Publisher: Wiley
Published: 2013-09-25T00:00:00+00:00


Designing the Sequencer

Now that you have all the elements in place you can begin to think about how you want this to look and operate. This is called top-down design because you start with a top-level view of what you want the software to look like.

I envisaged a grid of squares, each one representing an LED and its position in the sequence. A column of eight squares would represent the states of the LEDs at any instance in the sequence. A marker under the column will indicate what LEDs are being lit at any time. A mouse click in one of these squares will toggle the LED.

In order to help set up the sequence there should be some control buttons, one to clear or turn off all the LEDs in all sequence positions, and another to toggle or invert all the LEDs. There should be control buttons to determine the speed of the sequence and finally one to select where to take the trigger to advance the sequence from. This last point is important if you want to synchronise the changing of the lights to the beat of the music. The sequence can either be stepped at a regular rate determined by the speed controls, or locked into the beat of the music. This last feature will require a little bit of extra hardware and is optional – you can skip it for now and add it later if you like.

Finally it would be good if all the colours used in the sequence software were customizable; that is, it should be easy to change by changing a single value at one point of the code only. This means that whenever you use a colour you do not hard code it in by putting the colour numbers into a function call, but rather use a variable to define that colour. Those variables for all the colours should be grouped in one place in the code for easy access.

Implementing the Sequencer

After designing the sequencer from the top down, when it comes to implementing the design it is better to write the code in what is known as a bottom-up implementation. That means starting at the lowest possible function and working your way up. Of course, if you just look at the finished code you don’t see that. I started by taking the window test program and writing the functions that showed the columns representing the LEDs in the sequence. Then I expanded it so that I could click on each LED to turn the box on or off. Next came the controls to clear and invert, followed by the step indicator. This was followed by the speed controls and at this point I added the code to actually output something to the LEDs. Finally the auto/external step control was added and the code tidied up. This might not be the sequence of building up a program that first springs to the mind of a beginner, but the idea is to do a little coding and then test.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.