Arduino color game (Bomber) using VGA library

Why not try it on a '1284P, 16K SRAM, lots more options.

CrossRoads: Why not try it on a '1284P, 16K SRAM, lots more options.

I have done quite a few video projects on the 1284, I love that thing ! I just like to try some trickier ideas now and again, trying to get blood out of a stone !

Another classic game is in progress...


...Arduino VGA snake

Hi, maybe someone can help me! I am using an Arduino Uno R3 and IDE 1.6.5 R5 for programming! The VGA-Output works, and also the Paddel-Controller are working.

When i am trying pong or bomber i can load it on my arduino with no Problems! But then my vga-monitor tells me there is no Signal!! I found out when i am commenting out the analogRead command then i get Video Output, but the paddels are not working!

void processInputs() { //wheelPosition = analogRead(WHEEL_PIN); buttonStatus = digitalRead(BUTTON_PIN) ; }

So it Looks like there is a problem between analoginputs and vga-output!

Dear Synd, I am using IDE 1.6.4

I just realized that in the wheel and button PIN definition it is written:

#define BUTTON_PIN A2 #define WHEEL_PIN 1

coud it be that it should be replaced with the following?

#define BUTTON_PIN A2 #define WHEEL_PIN A1

in my IDE version both sintax works... This is the simplest thing coming in my mind at the moment. If it does not work, could you try other pins, just to see what happens (not A0 which is used for sound!).

Hi, thanks for feedback! I made already a correction of the ports according to my connections. And i tested already in a seperate sketch the paddels. They are working. Its a strange behavior of the vga-output when the analogRead command is used in the sketch. Looks like there is somthing happening to the timing. When i comment out the two lines with the analogRead in your sketch, i get a vga-output. But when i remove the comment, then i got no signal on my monitor! I already tried ide 1.6.4, makes no difference. The digitalRead of the buttons work!

Do you have a signal on your monitor with this?

  • wheelPosition =* 1023*digitalRead(WHEEL_PIN);
  • buttonStatus = digitalRead(BUTTON_PIN) ;*

Which pin have you used for the paddles? Only A1 to A5 work of course. Are your paddles 10 kOhm potenziometers or similar?

Sorry, I do not have many other ideas...

rob_cai: wheelPosition = 1023*digitalRead(WHEEL_PIN);

Why would you want to do this? Especially as it will almost certainly overflow an int.

Hi Odometer, why this should overflow an int? digitalRead(WHEEL_PIN) is either 1 or 0 thus WheelPosition is either 1023 or 0. Which means that the paddle will only stay in the two extreme positions on the monitor.

I tryed with Bomber and it works in this way. The reason to try this is that (if I am right) digitalRead() is less time consuming than analogRead(), since the latter "takes about 100 microseconds to read an analog input".

If this is the problem, i.e. digitalRead works, there is a method to make analogRead faster (with a reduction of precision, but you do not really need 1024 points, in principle only 120 for Bombard and 60 for Pong).

Before trying this (not trivial) modification, I want to see if it is really a problem of the command analoRead() or something else...

Of course I still do not understand why Synd has this problem...

Yes this works! I think also that there is a problem with the timing! But i am using a standard Arduino UNO V3! Did you ever update the bootloader? But its true, only when using the analogRead Command i get no vga output! digitalRead Works!
I have two paddels 10k pot on Pin A1 and A3 and the two buttons on A2 and A4! On A0 i connected a buzzer! So i found out that the game is working also when the vga is bad!

I have two standard Arduino uno R3 (of different ages, with the reset button in different position and different pin number) and an Arduino Uno SMD edition - all originals - and an Arduino nano - not original. Bomber and Pong work in all of them.

I never update the bootlander... I even do not know what does it means! Did you update it?

In Tools/programmer I have left the default setting: AVRISP mkII - (I don't know either what does it means)

In the past I have done a sketch where I have reduced the analogRead() timing (and precision). I can try to implement it in Pong, if you like (and if it works).

Yes please, i have also not upgraded or changed the bootloader! I have two Arduino R3 one original and one chinese! On both it doesnt work! I also think its a timing problem with the 100ms! It's only crazy, there are so many out where it works! So i try to find out whats maybe the difference! Thanks for help!

PS. I also have a Mega2650 but there the VGAX doesnt work -> the basic examples from the library doesnt work!

Dear Synd,
here it is Pong version 1.3, with a faster analogRead()!

I added the following instructions:

   // Define various ADC prescaler
const unsigned char PS_2 = (1 << ADPS0);
const unsigned char PS_4 = (1 << ADPS1);
const unsigned char PS_8 = (1 << ADPS1 | 1 << ADPS0);
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

and later on

     // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library
     // you can choose a prescaler from above.
     // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_4;    // set our own prescaler to 4. N.B. PS_2 does not work!!!

I tryed the new sketch and it works, but on my Arduino it was working also before, thus you should really try and test it!

By default, analogRead() takes about 100 microseconds to read an analog input.
The reason is because there is a “prescalar factor” equal to 128 which set the clock frequency of analogRead() at about 125 kHz. Reducing this factor to - say - 16, it does is a reading every 18 us (56 kHz).
With a prescalar factor equal to 4, there is a reading every 8 us, loosing some precision. With a P.F. = 2 analogRead does not work anymore.

A more complete description can be found here:

Please, let me know if it works. You can be the first beta tester! :wink:

pong_VGAx_v1.3.ino (20 KB)

Still not working! Commenting the analogRead command -> it works, with analogRead -> no vga signal! I ordered 2 Arduino Kits for breadboard! When i get them, i try it again! Thanks for help! When transfering the sketch to the UNO, i get always a low memory warning, but i think this is normal!

That’s a pity! I do not understand why you have this behaviour!
Does anybody have the same problem?

The low memory warning is normal, I have it as well.

pong_VGAx_v1.3.ino works ok. May be a hardware problem.

Today i got my arduino-kit. Everything works, i tried also the atmega328P from my uno-board, and it works! Looks like there is something strange going on with the uno-board! Many thanks for help.

Very good news. Still I cannot understand why it does not work on other board versions. But - from a pragmatic point of view - the problem is solved. I hope you can enjoy the game now!

Yes everthing works as expected This is a picture of my setup! I also dont really understand why the original board has the problem! Because the atmega328P is working! Yes i enjoy the game, reminds me of my childhood :slight_smile:

Wich picture?