Accelerometer Game
Frogger-G: An accelerometer game on MBED LPC1768
Overview
For the Mbed mini project, I developed a simple game that uses an ARM Microcontroller (LPC 1768), an accelerometer, a smart color LCD and a speaker. The technical specifications for the parts are mentioned in detail later.
The game is inspired by the popular arcade game ‘Frogger’. The frog follows the movement of the accelerometer and the goal of the game is to direct the frog to the other side of the street while avoiding the cars.
The code for the game was developed in C++ using the mbed cloud compiler. I have used the mbed’s Real Time Operating System (RTOS) to implement various threads that control the different components of the game. Mutex locks are used to access the shared resource (LCD) between the threads. The different thread functions are as follows:
- Thread 1 : Moves the red car. Runs update twice per second.
- Thread 2 : Moves the red car. Runs update 5 times per second.
- Thread 3 : Sound effect for the moving cars. Runs update twice per second.
- Thread 4 (main thread) : Checks the accelerometer readings to control the position of the frog.
Also detects collision between the cars and the frog and updates the status of the game (Game over or User wins).
Demo
Components and Technical specifications:
1. NXP LPC1678 microcontroller
2. ADXL345 accelerometer :
The ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g.
Digital output data is accessed through an SPI bus
Connections
MBED pin | ADXL345 Signal Name | |
---|---|---|
Vout | Vcc | |
Gnd | Gnd | |
SDA | p5 | |
SDO | p6 | |
SCL | p7 | |
CS | p8 |
3. uLCD-144-G2 128 by 128 Smart Color LCD Connections
MBED pin | LCD Signal Name | |
---|---|---|
VU | 5V | |
Gnd | Gnd | |
TX | RX | |
RX | TX | |
p11 | Reset |
4. Analog Speaker:
Hooking up the speaker directly to an mbed output pin results in very low volume and a driver circuit is needed to boost the current levels to drive the speaker to provide adequate volume levels. Hence the power transistor is used
Connections
Program
The code can be imported from http://mbed.org/users/yhazrat3/code/frogger_G/
References
- https://mbed.org/cookbook/ADXL345-Accelerometer
- https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/
- https://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
1 comment on Accelerometer Game:
Please log in to post comments.
please give the circuit diagram for this project.