Need for Speed Car
Overview
This Mbed mini project game resembles the most basic factors of a racing car game: running an object forward while avoiding the big rectangle obstacles on the way. It uses an ARM Microcontroller (LPC 1768), a smart color LCD(uLCD-144-G2), and a combination taking the advantages of multiple parallel sensors: Phidget rotation sensor, a Phidget force sensor, and a Phidget touch sensor.
Set-up on breadboard
Main interactions
Rotation sensor (the middle sensor)
to move the the main object to either left (rotate counter-clockwise) or right (rotate clockwise) to avoid the big rectangle obstacles.
Force sensor (the left sensor)
to press on it to speed up the moving of the obstacles. The harder the press is, the faster the obstacles move.
Touch sensor (the right sensor)
to cheat on the game. Every touch will allow one reverse of the timer countdown, making the obstacles to move backward. There is a maximum of three cheats per game.
The start screen of the game
Necessary parts
Main Code
The implementation of all the other threads are described in the header file called "head.h", which also includes all the other additional library files, and the rest of the implementation.
main.cpp
#include "head.h" void start(); void forward(void const *args); void steering(void const *args); void obstacle(void const *args); int main(void) { start(); while(timer); Thread thread1(steering); Thread thread2(obstacle); Thread thread3(forward); while (1) { stdio_mutex.lock(); int wait=450*force; lcd.locate(13,0); lcd.printf("%d",--count); Thread::wait(600-wait); if(count==0) { lcd.cls(); lcd.locate(1,8); lcd.printf("Congrats You win!"); exit(0); } stdio_mutex.unlock(); } }
Program
Demo
Please log in to post comments.