Finished the game

Dependencies:   mbed

Welcome to Snake

See that the LCD is on and press start to play

The snake is in the middle of the screen, move the analogue up, down, right, left to move the snake in those directions. Note that snake doesn't travel diagonally.

Move the snake to get as much food as possible, there is plenty of food as you will find out

Beware, snake will die if you run its head into the walls, or into its body

Take care to keep moving snake fast, its body will catch up with its head and cause it to die!!!!!!

Have fun, and get that snake as long as possible :)

Committer:
el18lg
Date:
Sat May 23 17:21:24 2020 +0000
Revision:
1:bdafa20e71a0
Started my map, making my way onto my snake programme;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18lg 1:bdafa20e71a0 1 /** @file FXOS8700CQ.h
el18lg 1:bdafa20e71a0 2
el18lg 1:bdafa20e71a0 3 @ brief FXOS8700CQ Library
el18lg 1:bdafa20e71a0 4
el18lg 1:bdafa20e71a0 5 @author Dr Craig A. Evans
el18lg 1:bdafa20e71a0 6 @brief (c) University of Leeds, Jan 2017
el18lg 1:bdafa20e71a0 7
el18lg 1:bdafa20e71a0 8 @code
el18lg 1:bdafa20e71a0 9
el18lg 1:bdafa20e71a0 10 #include "mbed.h"
el18lg 1:bdafa20e71a0 11 #include "FXOS8700CQ.h"
el18lg 1:bdafa20e71a0 12
el18lg 1:bdafa20e71a0 13 // create object and specifiy pins
el18lg 1:bdafa20e71a0 14 FXOS8700CQ device(I2C_SDA,I2C_SCL);
el18lg 1:bdafa20e71a0 15
el18lg 1:bdafa20e71a0 16 int main()
el18lg 1:bdafa20e71a0 17 {
el18lg 1:bdafa20e71a0 18 // call initialisation method
el18lg 1:bdafa20e71a0 19 device.init();
el18lg 1:bdafa20e71a0 20
el18lg 1:bdafa20e71a0 21 while (1) {
el18lg 1:bdafa20e71a0 22
el18lg 1:bdafa20e71a0 23 // poll the sensor and get the values, storing in a struct
el18lg 1:bdafa20e71a0 24 Data values = device.get_values();
el18lg 1:bdafa20e71a0 25
el18lg 1:bdafa20e71a0 26 // print each struct member over serial
el18lg 1:bdafa20e71a0 27 printf("ax = %f ay = %f az = %f | mx = %f my = %f mz = %f\n"
el18lg 1:bdafa20e71a0 28 ,values.ax, values.ay, values.az
el18lg 1:bdafa20e71a0 29 ,values.mx, values.my, values.mz);
el18lg 1:bdafa20e71a0 30
el18lg 1:bdafa20e71a0 31 wait(0.5);
el18lg 1:bdafa20e71a0 32 }
el18lg 1:bdafa20e71a0 33 }
el18lg 1:bdafa20e71a0 34
el18lg 1:bdafa20e71a0 35 @endcode
el18lg 1:bdafa20e71a0 36
el18lg 1:bdafa20e71a0 37 */
el18lg 1:bdafa20e71a0 38
el18lg 1:bdafa20e71a0 39 #ifndef FXOS8700CQ_H
el18lg 1:bdafa20e71a0 40 #define FXOS8700CQ_H
el18lg 1:bdafa20e71a0 41
el18lg 1:bdafa20e71a0 42 #include "mbed.h"
el18lg 1:bdafa20e71a0 43
el18lg 1:bdafa20e71a0 44 // mbed API uses 8-bit addresses so need to left-shift 7-bit addresses by 1
el18lg 1:bdafa20e71a0 45 #define FXOS8700CQ_ADDR (0x1D << 1) // for K64F board
el18lg 1:bdafa20e71a0 46 // values from 13.2 datasheet
el18lg 1:bdafa20e71a0 47 #define FXOS8700CQ_STATUS 0x00
el18lg 1:bdafa20e71a0 48 #define FXOS8700CQ_WHO_AM_I 0x0D
el18lg 1:bdafa20e71a0 49 #define FXOS8700CQ_XYZ_DATA_CFG 0x0E
el18lg 1:bdafa20e71a0 50 #define FXOS8700CQ_CTRL_REG1 0x2A
el18lg 1:bdafa20e71a0 51 #define FXOS8700CQ_M_CTRL_REG1 0x5B
el18lg 1:bdafa20e71a0 52 #define FXOS8700CQ_M_CTRL_REG2 0x5C
el18lg 1:bdafa20e71a0 53 #define FXOS8700CQ_WHO_AM_I_VAL 0xC7
el18lg 1:bdafa20e71a0 54 #define FXOS8700CQ_READ_LEN 13
el18lg 1:bdafa20e71a0 55
el18lg 1:bdafa20e71a0 56 #define PI 3.14159265359f
el18lg 1:bdafa20e71a0 57 #define RAD2DEG 57.2957795131f
el18lg 1:bdafa20e71a0 58
el18lg 1:bdafa20e71a0 59 struct Data {
el18lg 1:bdafa20e71a0 60 float ax;
el18lg 1:bdafa20e71a0 61 float ay;
el18lg 1:bdafa20e71a0 62 float az;
el18lg 1:bdafa20e71a0 63 float mx;
el18lg 1:bdafa20e71a0 64 float my;
el18lg 1:bdafa20e71a0 65 float mz;
el18lg 1:bdafa20e71a0 66 };
el18lg 1:bdafa20e71a0 67
el18lg 1:bdafa20e71a0 68 class FXOS8700CQ
el18lg 1:bdafa20e71a0 69 {
el18lg 1:bdafa20e71a0 70
el18lg 1:bdafa20e71a0 71 public:
el18lg 1:bdafa20e71a0 72 FXOS8700CQ(PinName sda, PinName scl);
el18lg 1:bdafa20e71a0 73 ~FXOS8700CQ();
el18lg 1:bdafa20e71a0 74 void init();
el18lg 1:bdafa20e71a0 75 Data get_values();
el18lg 1:bdafa20e71a0 76
el18lg 1:bdafa20e71a0 77 private:
el18lg 1:bdafa20e71a0 78 I2C* i2c;
el18lg 1:bdafa20e71a0 79
el18lg 1:bdafa20e71a0 80 void send_byte_to_reg(char byte,char reg);
el18lg 1:bdafa20e71a0 81 char read_byte_from_reg(char reg);
el18lg 1:bdafa20e71a0 82 void read_bytes_from_reg(char reg,int number_of_bytes,char bytes[]);
el18lg 1:bdafa20e71a0 83 };
el18lg 1:bdafa20e71a0 84
el18lg 1:bdafa20e71a0 85 #endif