COMPONENTS AND SUPPLIES
APPS AND ONLINE SERVICES
ABOUT THIS PROJECT
Overview
First of all we build the game controller, using a button and an accelerometer. I use a GY-521, so if you use a different accelerometer you will need to change part of the code.
Connections for the accelerometer and the button
- VCC -> 5 V
- GND -> GND
- SCL -> A5
- SDA -> A4
Connect the button to the digital pin 7 and connect it to ground with a 10 Kohm resistor. Then connect the supply to 5 V.
How to make it
In the code we use the Bounce library in order to avoid the bounce of the signal of the button. Download the library and copy the unzipped folder in the libraries folder of Arduino.
I use a standard breadboard but it's a bit difficult moving the controller. It would be better to use an Arduino Prototyping shield.
To create the game we use Processing, which can be downloaded here. First you run the Arduino code. Then run the Processing code.
Wait for the accelerometer to stabilize. Press the button and the game will start. Moving the accelerometer along the X axis the paddle will move.
Be mindful of port
Check the Processing code. Maybe you need to change the instruction:arduinoPort=new Serial(this, "COM3", 19200); Instead of COM3 you have to use the port you are using with Arduino. Also Processing and Ardruino must have the same baud rate.
ไม่มีความคิดเห็น:
แสดงความคิดเห็น