I’m still waiting for my cheap Bluetooth module from China which will serve as an input interface for my scoreboard project. In the meantime, I’ll show you how to convert your ATtiny microcontroller into a Pong game (with no input so far).
So, I’ve used the scoreboard source as a base and changed a little bit the pinout.
Now the RGB is connected to PB0, and there is a good reason for this. I’m still using the same technique of storing what I want to render in registers but instead of 4, this time I’m using 15 so I can achieve an horizontal resolution of 120 by 96 to make the pixels somehow squared. Now, to be able to walk trough the 120 bits and turn the RGB pin on/off accordingly (and evenly) I needed to crop the code, removing the loops (so you will see a lot of similar code in the part that renders the line) and the conditional skip now replaced by an “add with carry” after the shift into a temporary register that will be used with “out” which is less expensive than “sbi” and “cbi”.
So, in terms of code optimization, this:
Is better than:
There are also other parts of the code that might be of interest. For example, I’ve use LFSR to add some pseudo-random variables to the ball direction and the paddle “computer” movements. Also, I’ve used the Bresenham’s line algorithm to determine the ball position.
The missing part, is still the input. I’m not sure how this will work with only one pin available, but I guess I’ll work out something with the Bluetooth module and one of the synch signals (if even possible).
I’ve tried to add some intro screen or “splash”, but the program memory is so small that I’ve quickly exceeded the 4096 available bytes.