Tuesday, March 22, 2011

Project 22 - LED Dot Matrix Display - Pong Game

After downloading the LedControl library and extracting it into the Arduino library folder, I uploaded the very simple program for project 22 to my Arduino. The only modification I made to the circuit built in Project 21 was adding the single potentiometer... mine is a 5k instead of the 10k specified which seems to make the response a little bit less reliable... no big deal as I totally understand the program and how it works.

I really have a new appreciation for those old-time programmers who had to code up all this stuff with limited memory, limited video controls, etc... makes all those years play Atari 2600 games seem even more fun.

An 8x8 LED is definitely going to limit what you can do in terms of games, but you can see how a larger display such as the LoL Shield expands your opportunities. I'm now looking forward to learning more about the LCD screen in the next chapter as it has a higher resolution and, apparently, less wiring and coding to get stuff displayed properly. (Reading ahead, I'm hoping that my 16x2 LCD is compatible with the HD44780 driver the author mentions in Chapter 8. Will find out shortly)

Below is a video of the Pong Game... trying to control the paddle with one hand while holding the camera is difficult, so don't laugh at the results!


  1. Awesome! I need to go through this book, but haven't had a chance. Will be good for young kids to play that game, since so many games online are too difficult.

  2. This is very frustrating. I bought a set of four common cathode displays for $10 on ebay, but after I connected everything, my display was flickering like when you had accidentally used the common anode display. For future readers, do NOT buy this model labeled SZ21288 because it did not work: http://detail.china.alibaba.com/buyer/offerdetail/687990840.html

    The strange thing is that the datasheet shows this model as a common cathode display.

  3. Jim, I am struggling to understand how all of the LEDs were still able to light up and flash when you had the common anode display connected instead of the common cathode. I tested each LED individually on my LED matrix that was advertised as "common cathode" and each lights up as expected according to the data sheet for the common cathode configuration (see link in my previous comment). Can anybody help me figure out this mystery?

  4. VKY,

    Not sure why you're not getting it to work - for this particular experiment I followed the instructions to the letter. Does your component have any part# on it that we can reference?

  5. I finally got it to work, so it turns out that these ARE common cathode displays after all. Here is what I did:

    1) Changed the resistor value from 100 ohms to 10,000 ohms. The book doesn't explicitly declare a resistor value, but I used brown-black-brown (100 ohms) based on the book schematic. I think the LED matrix may have been sinking too much current.

    2) Reconnected the Dig lines to the cathodes (rows) and Seg lines to the anodes (columns). I believe the book has it in reverse, but I found this link to clarify the wiring:

    Now to try and understand how the code works! =)


  6. Victor, you saved me a ton of effort by figuring out that resistor issues. Thanks.

  7. Hi James,
    I wonder if you are still here as this is a bit late..I will try to explain: I finally got project 21 working..First it needed the Block deleted then after that it would compile..I got the scroll but a mirror image ..Instead of right to left scroll it was from left to right..Also the letters were backwards..That was solved when I switched row 1 to row 8 and everything in between..It then worked perfectly..My guess it was a difference in the LED Matrix although it agreed with the authors pictorial..OH Well!!
    I moved on to project 22..IDE, "compiler errors"..The one with the small block had to be deleted as in 21..Then it says "My Matrix was not declared in this scope"
    Did you run into that when you got the pong working?
    Thank you

  8. Update: After reading your post again I realized that I completely missed the LEDcontrol library..
    I had a bit of trouble in Linux getting the Ownership and permissions correct..But once that was solved,
    It works like it should.My stupid mistake.
    Thanks again for your post,

  9. I get error messages: "byte" does not name a type and "byte" has not been declared and "boolean" has not been declared in Project 22 Pong game. Please help.
    Thank you, Steve

  10. how about if im add AI (artificial intelegent) in game ? and made 3 levels easy,medium and hard ? any sugesst reference ?