You might not be familiar with some of the C operations here << means shift to the right a number of times. So that 1 << 8 will actually generate a number 0x100. The & is the bit wise and operation and is used to probe the individual bits in a byte.







So the software will build up an array of bit patterns (numbers) to send to the LEDs in turn. These are then fired at the hardware at a regular rate to produce the flashing pattern we need. This is synchronised to your swing by looking when the motion switch changes direction. This then triggers one scan through the display array. It is best to introduce a small delay from the change in the switch before starting the display to allow the stick to come up to speed.







Now reliable delays are not a strong point of a multitasking environment like Linux. Fortunately the BCM2835 chip has an ARM peripheral that can help. It is a free running counter, that means it keeps on going while the operating system steals some time off you. So when you want a delay you simply make a note of the value in the counter at the start and don't return until the counter has advanced to a value corresponding tot he delay you want. The only snag is that time might be being stolen off you just when the counter is about to expire, in which case the delay will be longer than you wanted, but most of the time it will be fine. I set up the prescalar to this counter so that it increments at a 1MHz rate giving me micro second resolution. There are other tricks you can pull like altering the priority of the task and using interrupts, but the results I obtained were good enough not to bother with these techniques. However, I found that the words were distorted when the screen saver kicked in. You can see in the image below, here the switching of the columns gets delayed to smear out the letters. Under normal operation the program spends most of its time sitting in a delay loop, interrupts here are not noticed. I must say that it looks much better in real life than it does in these photographs.







Also, I think you get better results if you just produce the scan on one swing and not both. This is because the position of the letters in the air is more consistent and does not change with forward and reverse swing.