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.

http://developer.mbed.org/media/uploads/sim91/img_20150309_235937412_hdr.jpg

Set-up on breadboard

http://developer.mbed.org/media/uploads/sim91/img_20150309_235912096_hdr.jpg

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

http://developer.mbed.org/media/uploads/sim91/img_20150310_240252361_hdr.jpg

Necessary parts

/media/uploads/sim91/ulcd.png

/media/uploads/sim91/table1.png

/media/uploads/sim91/rotation_sensor.png

/media/uploads/sim91/r.png

/media/uploads/sim91/touch_sensor.png

/media/uploads/sim91/t.png

/media/uploads/sim91/force_sensor.png

/media/uploads/sim91/f.png

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

Import program4180_lab4_Mini_Project

lab4

Demo


Please log in to post comments.