The present code implements a single player squash game, using joystick to move paddle right or left. And checks the current temperature inside the device.

Dependencies:   mbed

Dependents:   Squash_Project

Committer:
bonnyngangu
Date:
Sun May 08 21:59:21 2016 +0000
Revision:
1:862da825ba95
Parent:
main.cpp@0:026fa541af7a
Last update for paddle movement.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bonnyngangu 1:862da825ba95 1 #include "mbed.h"
bonnyngangu 1:862da825ba95 2 #include "N5110.h" // to enable access and use of the N5110 classes.
eencae 0:026fa541af7a 3
bonnyngangu 1:862da825ba95 4 #define DIRECTION_TOLERANCE 0.25 // changing to this value enables altering tolerance of joystick direction
bonnyngangu 1:862da825ba95 5 #ifndef GAME_H
bonnyngangu 1:862da825ba95 6 #define GAME_H
eencae 0:026fa541af7a 7
bonnyngangu 1:862da825ba95 8 Ticker pollJoystick;// regular reading of the joystick position.
bonnyngangu 1:862da825ba95 9 Serial serial(USBTX,USBRX);// Serial for debug
eencae 0:026fa541af7a 10
bonnyngangu 1:862da825ba95 11 //create enumerated type (0,1,2,3 etc. for direction)
bonnyngangu 1:862da825ba95 12 //could be extended for diagonals etc.
eencae 0:026fa541af7a 13
eencae 0:026fa541af7a 14 enum DirectionName {
eencae 0:026fa541af7a 15 UP,
eencae 0:026fa541af7a 16 DOWN,
eencae 0:026fa541af7a 17 LEFT,
eencae 0:026fa541af7a 18 RIGHT,
eencae 0:026fa541af7a 19 CENTRE,
eencae 0:026fa541af7a 20 UNKNOWN
eencae 0:026fa541af7a 21 };
eencae 0:026fa541af7a 22
bonnyngangu 1:862da825ba95 23 typedef struct JoyStick Joystick;// for Joystick structure
bonnyngangu 1:862da825ba95 24
eencae 0:026fa541af7a 25 struct JoyStick {
eencae 0:026fa541af7a 26 float x; // current x value
eencae 0:026fa541af7a 27 float x0; // 'centred' x value
eencae 0:026fa541af7a 28 float y; // current y value
eencae 0:026fa541af7a 29 float y0; // 'centred' y value
bonnyngangu 1:862da825ba95 30 int buttonjoystick; /// button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
bonnyngangu 1:862da825ba95 31 DirectionName direction; /// current direction
eencae 0:026fa541af7a 32 };
bonnyngangu 1:862da825ba95 33
bonnyngangu 1:862da825ba95 34 Joystick joystick;// creating struct variables
bonnyngangu 1:862da825ba95 35
bonnyngangu 1:862da825ba95 36 volatile int g_button_flag = 0;// setting the "g_button_flag" original value to Zero.
eencae 0:026fa541af7a 37
eencae 0:026fa541af7a 38
bonnyngangu 1:862da825ba95 39 // initialising joystick position.
eencae 0:026fa541af7a 40 void calibrateJoystick();
bonnyngangu 1:862da825ba95 41
bonnyngangu 1:862da825ba95 42 // reading the current value of joystick .
eencae 0:026fa541af7a 43 void updateJoystick();
eencae 0:026fa541af7a 44
bonnyngangu 1:862da825ba95 45 void button_isr();
eencae 0:026fa541af7a 46
bonnyngangu 1:862da825ba95 47 int status = 1;// setting the status at the origin.
bonnyngangu 1:862da825ba95 48 int printFlag = 0;// this sets Flags value to Zero
eencae 0:026fa541af7a 49
bonnyngangu 1:862da825ba95 50 // enabling boolean expression.
bonnyngangu 1:862da825ba95 51 bool wall = false;
bonnyngangu 1:862da825ba95 52 bool hit = false;
bonnyngangu 1:862da825ba95 53 bool bullethit = false;
eencae 0:026fa541af7a 54
bonnyngangu 1:862da825ba95 55 #endif