Go Down

Topic: Arduino color game (Bomber) using VGA library (Read 314 times) previous topic - next topic

rob_cai

Jun 09, 2015, 12:55 am Last Edit: Jul 01, 2015, 02:28 pm by rob_cai


Hello to all,
thanks to the VGAx library done by Smaffer, based on the previous work done by Nick Gammon, I have done a little color game for an Arduino Uno working for a VGA monitor. See for details here:

The target was to use an Arduino Uno board without special shields and supporting IC.
the fundamental components are a button, a potenziometer, few resistors and DSUB15 connector.

For the VGA library, the DSUB15 connections, and for the color choice, please refer to smaffer post:

The potenziometer should be connected to analogue pin 2 (A2), the button to analogue pin 1 (A1) and the buzzer to A0.

The code is attached here.
Enjoy!

NB an update of the game (version 02) is available in this post at #6

zoomx

The potenziometer should be connected to analogue pin 2 (A2), the button to analogue pin 1 (A1) and the buzzer to A0.
In the sketch I found this
Code: [Select]
#define BUTTON_PIN 0  //NB: by default, this pin (A0) is used in the VGAx library to generate the audio.
//#define BUTTON_PIN 2
#define WHEEL_PIN 1


It seems that button pin is on A0. Why you used an analogue pin?
Anyway I agree Nick Gammon: Very impressive!

rob_cai

Good question! And thank you for the positive comment!

This is an "inheritance" of a previous code, i.e. Arduino Bomber B&W with TVout library that I did before the VGA version (see here).
I had problem in the past with the digitalRead command (sorry, I forgot the details).

By the way, later on I trasform the "analog" read of the button in a 0 - 1 form with the following part:

Code: [Select]

void processInputs() {
  wheelPosition = analogRead(WHEEL_PIN);
  buttonStatus = (analogRead(BUTTON_PIN) > 512);
}


and thus buttonStatus became either 1 or 0.
This is an inelegant solution but it works...

zoomx

I don't understand the use of the analog pin in this way since you can use the analog pin as digital as written here
http://www.arduino.cc/en/Tutorial/AnalogInputPins


Quote
Pin mapping


The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:


pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
[/pre]
Anyway this is a sketch that I must try! :)

rob_cai

#4
Jun 09, 2015, 10:49 pm Last Edit: Jun 09, 2015, 10:51 pm by rob_cai
dear zoomx,
I applied the correction you suggest. The behaviour is the same but the code is more understandable.
Now the code has:

Code: [Select]

#define BUTTON_PIN A0
//#define BUTTON_PIN A2
.
.
.
void processInputs() {
  wheelPosition = analogRead(WHEEL_PIN);
  buttonStatus = digitalRead(BUTTON_PIN) ;
}


instead of:

Code: [Select]

#define BUTTON_PIN 0
//#define BUTTON_PIN 2
.
.
.
void processInputs() {
  wheelPosition = analogRead(WHEEL_PIN);
  buttonStatus = (analogRead(BUTTON_PIN) > 512);
}


I understand a bit more now!
I am glad you want to try it. Let me know!

smaffer

Good work Rob Cai!
Your game is the first that use VGAX! In the next commit i will add your game in the github notes.
Thank you!

rob_cai

#6
Jun 14, 2015, 10:43 pm Last Edit: Jun 15, 2015, 12:36 am by rob_cai
A second version of "Arduino Bomber" is ready!

It uses the recent "VGAXUtils.h" written by Smaffer, to draw lines, circles, rectangles, and so on (see his post for details).

The code has needed deep modifications to be compatible with these functions, but the screen is now drawn roughly ten times faster and the game became more smooth and precise.

The code is attached here.
As said before: enjoy!

mcnobby

while (z--) { snoreEvenLouder(); }
www.smartshow.lighting - www.dmx512.lighting

rob_cai

#8
Jun 20, 2015, 10:40 pm Last Edit: Jun 20, 2015, 10:49 pm by rob_cai
I have done a "new" game:

Pong with colors and sound, running for a VGA monitor.

Link to the video here:

As for "Bomber", this game does not need a special shield or support chips, but just few resistors, a DSUB15 connector, a pair of potenziometers and a buttons.

Since I am using only one potenziometer and button, the two paddles move in parallel. Anyway, the code is ready for the "second player".

The code is at the bottom.
Enjoy!


Go Up