Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

FXOS8700CQ/FXOS8700CQ.h

Committer:
evanso
Date:
2020-05-27
Revision:
87:832ca78426b5
Parent:
48:e308067cfea5

File content as of revision 87:832ca78426b5:

/** @file FXOS8700CQ.h

@ brief FXOS8700CQ Library

@author Dr Craig A. Evans
@brief (c) University of Leeds, Jan 2017

@code

#include "mbed.h"
#include "FXOS8700CQ.h"

// create object and specifiy pins
FXOS8700CQ device(I2C_SDA,I2C_SCL);

int main()
{
    // call initialisation method
    device.init();

    while (1) {
        
        // poll the sensor and get the values, storing in a struct
        Data values = device.get_values();
        
        // print each struct member over serial
        printf("ax = %f ay = %f az = %f | mx = %f my = %f mz = %f\n"
               ,values.ax, values.ay, values.az
               ,values.mx, values.my, values.mz);
        
        wait(0.5);
    }
}

@endcode

*/

#ifndef FXOS8700CQ_H
#define FXOS8700CQ_H

#include "mbed.h"

// mbed API uses 8-bit addresses so need to left-shift 7-bit addresses by 1
#define FXOS8700CQ_ADDR   (0x1D << 1)    // for K64F board
// values from 13.2 datasheet
#define FXOS8700CQ_STATUS 0x00
#define FXOS8700CQ_WHO_AM_I 0x0D
#define FXOS8700CQ_XYZ_DATA_CFG 0x0E
#define FXOS8700CQ_CTRL_REG1 0x2A
#define FXOS8700CQ_M_CTRL_REG1 0x5B
#define FXOS8700CQ_M_CTRL_REG2 0x5C
#define FXOS8700CQ_WHO_AM_I_VAL 0xC7
#define FXOS8700CQ_READ_LEN 13


#define RAD2DEG 57.2957795131f

struct Data {
    float ax;
    float ay;
    float az;
    float mx;
    float my;
    float mz;
};

class FXOS8700CQ
{

public:
    FXOS8700CQ(PinName sda, PinName scl);
    ~FXOS8700CQ();
    void init();
    
// Accessors and mutators --------------------------------------------------
            
    Data get_values();
    
    /** Gets gamepad roll angle
     * @return roll_angle 
     */
    float get_roll_angle();
    
    /** Gets gampad pitch angle
     * @return pitch_angle 
     */
    float get_pitch_angle();
    
private:
    I2C* i2c;

    void send_byte_to_reg(char byte,char reg);
    char read_byte_from_reg(char reg);
    void read_bytes_from_reg(char reg,int number_of_bytes,char bytes[]);
};

#endif