![](/media/cache/profiles/859bf1416b8b8761c5d588dee78dc65f.50x50_q85.jpg)
Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
PanelControls.h@18:70190f956a24, 2013-06-17 (annotated)
- Committer:
- RichardE
- Date:
- Mon Jun 17 15:10:43 2013 +0000
- Revision:
- 18:70190f956a24
- Parent:
- 4:673eb9735d44
Improved response to button 1 when entering high scores (HighScoreEntry.cpp).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichardE | 4:673eb9735d44 | 1 | /* |
RichardE | 4:673eb9735d44 | 2 | * SOURCE FILE : PanelControls.h |
RichardE | 4:673eb9735d44 | 3 | * |
RichardE | 4:673eb9735d44 | 4 | * Responsible for reading joysticks and buttons. |
RichardE | 4:673eb9735d44 | 5 | * This is the version for mbed LPC1768. |
RichardE | 4:673eb9735d44 | 6 | * There is a version kicking around for the LPC11U24 that uses different inputs for joystick 2. |
RichardE | 4:673eb9735d44 | 7 | * |
RichardE | 4:673eb9735d44 | 8 | */ |
RichardE | 4:673eb9735d44 | 9 | |
RichardE | 4:673eb9735d44 | 10 | #ifndef PanelControlsIncluded |
RichardE | 4:673eb9735d44 | 11 | |
RichardE | 4:673eb9735d44 | 12 | #define PanelControlsIncluded |
RichardE | 4:673eb9735d44 | 13 | |
RichardE | 4:673eb9735d44 | 14 | #include "mbed.h" |
RichardE | 4:673eb9735d44 | 15 | #include "Types.h" |
RichardE | 4:673eb9735d44 | 16 | |
RichardE | 4:673eb9735d44 | 17 | class PanelControls { |
RichardE | 4:673eb9735d44 | 18 | |
RichardE | 4:673eb9735d44 | 19 | public : |
RichardE | 4:673eb9735d44 | 20 | |
RichardE | 4:673eb9735d44 | 21 | /***************/ |
RichardE | 4:673eb9735d44 | 22 | /* CONSTRUCTOR */ |
RichardE | 4:673eb9735d44 | 23 | /***************/ |
RichardE | 4:673eb9735d44 | 24 | PanelControls() : |
RichardE | 4:673eb9735d44 | 25 | inputs( 0 ), |
RichardE | 4:673eb9735d44 | 26 | bus( (BusIn*)NULL ) |
RichardE | 4:673eb9735d44 | 27 | { |
RichardE | 4:673eb9735d44 | 28 | } |
RichardE | 4:673eb9735d44 | 29 | |
RichardE | 4:673eb9735d44 | 30 | /**************/ |
RichardE | 4:673eb9735d44 | 31 | /* DESTRUCTOR */ |
RichardE | 4:673eb9735d44 | 32 | /**************/ |
RichardE | 4:673eb9735d44 | 33 | ~PanelControls() { |
RichardE | 4:673eb9735d44 | 34 | delete bus; |
RichardE | 4:673eb9735d44 | 35 | } |
RichardE | 4:673eb9735d44 | 36 | |
RichardE | 4:673eb9735d44 | 37 | /*************************/ |
RichardE | 4:673eb9735d44 | 38 | /* INITIALISE INPUT PINS */ |
RichardE | 4:673eb9735d44 | 39 | /*************************/ |
RichardE | 4:673eb9735d44 | 40 | void InitialisePins( void ) { |
RichardE | 4:673eb9735d44 | 41 | // Create an input bus. |
RichardE | 4:673eb9735d44 | 42 | bus = new BusIn( |
RichardE | 4:673eb9735d44 | 43 | p23, p24, p25, p26, // joystick 1 up, down, left, right |
RichardE | 4:673eb9735d44 | 44 | p21, p22, p27, p28, // joystick 2 up, down, left, right |
RichardE | 4:673eb9735d44 | 45 | p29, p30 // button 1, button 2 |
RichardE | 4:673eb9735d44 | 46 | ); |
RichardE | 4:673eb9735d44 | 47 | } |
RichardE | 4:673eb9735d44 | 48 | |
RichardE | 4:673eb9735d44 | 49 | /*****************************/ |
RichardE | 4:673eb9735d44 | 50 | /* READ ALL THE PANEL INPUTS */ |
RichardE | 4:673eb9735d44 | 51 | /*****************************/ |
RichardE | 4:673eb9735d44 | 52 | // Returns a bitmap of all the inputs. |
RichardE | 4:673eb9735d44 | 53 | void Read( void ) { |
RichardE | 4:673eb9735d44 | 54 | if( bus == (BusIn*)NULL ) { |
RichardE | 4:673eb9735d44 | 55 | inputs = 0; |
RichardE | 4:673eb9735d44 | 56 | } |
RichardE | 4:673eb9735d44 | 57 | else { |
RichardE | 4:673eb9735d44 | 58 | // Note that a closed contact registers as a zero |
RichardE | 4:673eb9735d44 | 59 | // which is why the bitwise not operator (~) is used. |
RichardE | 4:673eb9735d44 | 60 | inputs = ~*bus & 0x3FF; |
RichardE | 4:673eb9735d44 | 61 | } |
RichardE | 4:673eb9735d44 | 62 | } |
RichardE | 4:673eb9735d44 | 63 | |
RichardE | 4:673eb9735d44 | 64 | // Masks to use with GetInputs method. |
RichardE | 4:673eb9735d44 | 65 | enum Mask { |
RichardE | 4:673eb9735d44 | 66 | Up1 = 1, |
RichardE | 4:673eb9735d44 | 67 | Down1 = 2, |
RichardE | 4:673eb9735d44 | 68 | Left1 = 4, |
RichardE | 4:673eb9735d44 | 69 | Right1 = 8, |
RichardE | 4:673eb9735d44 | 70 | Up2 = 16, |
RichardE | 4:673eb9735d44 | 71 | Down2 = 32, |
RichardE | 4:673eb9735d44 | 72 | Left2 = 64, |
RichardE | 4:673eb9735d44 | 73 | Right2 = 128, |
RichardE | 4:673eb9735d44 | 74 | Button1 = 256, |
RichardE | 4:673eb9735d44 | 75 | Button2 = 512, |
RichardE | 4:673eb9735d44 | 76 | }; |
RichardE | 4:673eb9735d44 | 77 | |
RichardE | 4:673eb9735d44 | 78 | // Bit numbers indicating where readings for each joystick start in the map. |
RichardE | 4:673eb9735d44 | 79 | // Can use these with right shift operator. |
RichardE | 4:673eb9735d44 | 80 | enum Bits { |
RichardE | 4:673eb9735d44 | 81 | Joy1 = 0, // joystick 1 readings start at bit 0 |
RichardE | 4:673eb9735d44 | 82 | Joy2 = 4, // joystick 2 readings start at bit 4 |
RichardE | 4:673eb9735d44 | 83 | Buttons = 8, // button readings start at bit 8 |
RichardE | 4:673eb9735d44 | 84 | }; |
RichardE | 4:673eb9735d44 | 85 | |
RichardE | 4:673eb9735d44 | 86 | /***************************/ |
RichardE | 4:673eb9735d44 | 87 | /* GET STATE OF THE INPUTS */ |
RichardE | 4:673eb9735d44 | 88 | /***************************/ |
RichardE | 4:673eb9735d44 | 89 | // Returns a bitmap of the state of the inputs |
RichardE | 4:673eb9735d44 | 90 | // last time Read was called. |
RichardE | 4:673eb9735d44 | 91 | UInt16 GetInputs( void ) { |
RichardE | 4:673eb9735d44 | 92 | return inputs; |
RichardE | 4:673eb9735d44 | 93 | } |
RichardE | 4:673eb9735d44 | 94 | |
RichardE | 4:673eb9735d44 | 95 | private : |
RichardE | 4:673eb9735d44 | 96 | |
RichardE | 4:673eb9735d44 | 97 | // Stored state of inputs. |
RichardE | 4:673eb9735d44 | 98 | UInt16 inputs; |
RichardE | 4:673eb9735d44 | 99 | |
RichardE | 4:673eb9735d44 | 100 | // Input bus used to read inputs. |
RichardE | 4:673eb9735d44 | 101 | BusIn *bus; |
RichardE | 4:673eb9735d44 | 102 | |
RichardE | 4:673eb9735d44 | 103 | }; |
RichardE | 4:673eb9735d44 | 104 | |
RichardE | 4:673eb9735d44 | 105 | #endif |
RichardE | 4:673eb9735d44 | 106 | |
RichardE | 4:673eb9735d44 | 107 | /* END of PanelControls.h */ |