ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

main.cpp

Committer:
shahidsajid
Date:
2019-04-18
Revision:
7:a1a6bff238c1
Parent:
6:3e50f2cf4366
Child:
8:7b7e1a5b8200
Child:
9:a81db6a703b7

File content as of revision 7:a1a6bff238c1:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Shahid Zubin Sajid
Username: el17szs   
Student ID Number: 201197609
Date: 21/03/2019
*/

#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Ball.h"
#include "Bat.h"


N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad1;
Ball ball;
Bat bat;

void init();

//void welcome();
void draw();
void ball_test();

int main(){
    int fps=8;
    init();
   // welcome();
    draw();
    /*
    while (1){
        draw();
        wait(1.0f/fps);
    }
    */
    float f;
    while(1){
        f= pad1.get_mag();
        printf("MAG %f \n",f);
        int lol=bat.get_hitBall();
        
        ball.start(lcd,lol,pad1.get_direction());
        draw();
        wait(1.0f/fps);
    }
    
    
    
}
void init(){
    lcd.init();
    pad1.init();
    bat.init(4,5);
    ball.init(2,3);
    //field.init();
    lcd.setContrast(0.4);
    lcd.normalMode();      // normal colour mode
    lcd.setBrightness(0.5);
    lcd.clear();
    
}
void welcome() {
    lcd.printString("     CRICKET GAME    ",0,1);  
    lcd.printString(" SHAHID SAJID",0,2); 
    lcd.printString("     el17szs    ",0,3);
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();
    // wait flashing LEDs until start button is pressed 
    while ( pad1.check_event(Gamepad::START_PRESSED) == false) {
        pad1.leds_on();
        wait(0.1);
        pad1.leds_off();
        wait(0.1);
    }
 
}
void draw(){
    lcd.clear();
    lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT);
    lcd.drawRect(37,11,12,30,FILL_TRANSPARENT);
    ball.draw(lcd);
    ball.set_field(lcd);
    bat.draw(lcd);
    lcd.refresh();
}
void ball_test(){
    Vector2D ball_pos = ball.get_pos();
    Vector2D ball_velocity = ball.get_velocity();
    ball.update();  
    
    ball.set_velocity(ball_velocity);
    ball.set_pos(ball_pos);
    ball.update(); 
}