Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ScoreCount by
main.cpp
00001 #include "mbed.h" 00002 #include "TSISensor.h" 00003 #include "TextLCD.h" 00004 #include "process_signal.h" 00005 #include "reciever.h" 00006 #include "transmitter.h" 00007 00008 00009 //RGB LED SETUP 00010 DigitalOut Red(PTC6); 00011 DigitalOut Blue(PTC10); 00012 DigitalOut Green(PTC11); 00013 00014 Serial pc(USBTX,USBRX); 00015 00016 //LCD SCREEN SETUP 00017 TextLCD lcd(PTD7, PTD6, PTA17, PTA16, PTC17, PTC16); // rs, e, d4-d7 00018 00019 //INITIAL PARAMETERS AND GLOBAL VARIABLES 00020 int hit=0; 00021 int lives=10; //How many lives to start game with 00022 unsigned char data[4]; 00023 unsigned char Ah=0; 00024 unsigned char Bh=0; 00025 unsigned char Ch=0; 00026 unsigned char Dh=0; 00027 char Player='A'; 00028 00029 //BEGIN! 00030 00031 int main() 00032 { 00033 while(1) 00034 { 00035 reset_array(); //At start of new game reset hits from players to 0 00036 00037 while (lives>=0) 00038 { 00039 Blue=1; //Blue light always on when playing 00040 Red=0; 00041 Green=0; 00042 00043 if (lives==0) 00044 { 00045 Green=1; //Turquoise if no lives remain (effectively last life left) 00046 } 00047 00048 00049 lcd.cls(); 00050 00051 lcd.locate(0,0); 00052 lcd.printf("Player %c \n", Player); //Print which player you are 00053 00054 lcd.locate(0,1); 00055 lcd.printf("Lives left: %d \n", lives); //Print how many lives are left 00056 00057 00058 //Have you been hit? 00059 00060 int signal; 00061 signal=Interrogate(); 00062 hit= process_signal(signal); 00063 00064 00065 lives--; 00066 00067 if(lives<0) 00068 { 00069 goto end; //Skip to the end (avoids read out of -1 lives) 00070 } 00071 00072 //Update lives on LCD 00073 00074 lcd.locate(0,1); 00075 lcd.printf("You've been hit!"); 00076 00077 //Flash to register hit 00078 unsigned char i; 00079 for(i=0;i<4;i++) //INCREASE i TO EXTEND TIME THAT GUN IS DISABLED! 00080 { 00081 Blue=0; 00082 Red=1; 00083 wait(0.2); 00084 Red=0; 00085 Blue=1; 00086 wait(0.2); 00087 } 00088 00089 } 00090 00091 end: 00092 00093 Blue=0; 00094 Green=0; 00095 lcd.cls(); 00096 lcd.locate(0,0); 00097 lcd.printf(" - GAME OVER - ...you suck"); 00098 00099 00100 unsigned char i; 00101 for(i=0;i<50;i++) //Flashing to indicate game over - INCREASE i FOR LONGER BREAK BEFORE RESET 00102 { 00103 Red=1; 00104 wait(0.05); 00105 Red=0; 00106 wait(0.05); 00107 } 00108 00109 //Pretty green light and resetting 00110 Green=1; 00111 lives= 10; 00112 wait(2); 00113 Green=0; 00114 lcd.cls(); 00115 } 00116 }
Generated on Mon Jul 18 2022 03:28:26 by
1.7.2
