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 congolcd by
main.cpp
00001 // Hello World! for the TextLCD 00002 00003 #include "mbed.h" 00004 #include "TextLCD.h" //header file to interact with LCD 16*2 00005 00006 00007 BusOut Disp2(p21,p22,p23,p24,p25,p26,p27,p5);//a.b.c.d.e.f.g.dp 00008 BusOut Disp1(p28,p29,p30,p33,p34,p35,p36,p5);//a.b.c.d.e.f.g.dp 00009 Serial pc(USBTX, USBRX); // tx, rx 00010 00011 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 00012 int z; 00013 int x=0; 00014 int y=0; 00015 int main() 00016 { pc.baud(9600); //fixing the baud rate of transmission to 9600 bits. 00017 00018 Disp1=0xC0; //setting the initial displays of seven segment to zero 00019 Disp2=0xC0; 00020 00021 00022 lcd.cls(); //clear screen function for lcd 00023 lcd.printf("** WELCOME **"); //initially printing on LCD 00024 wait(2); // 2 second waiting time before proceeding further 00025 lcd.cls(); 00026 lcd.printf("PLAYER-1... "); 00027 lcd.printf("%i \n",x); //fetching current player 1 score 00028 lcd.printf("PLAYER-2... "); 00029 lcd.printf("%i",y);//fetching current player 2 score 00030 00031 while(1) 00032 { 00033 char c = pc.getc(); //get character serially 00034 char d = pc.getc(); 00035 pc.printf("%c",c); 00036 pc.printf("%c",c); 00037 if(c == '0') 00038 Disp1=0xC0; //display fetched Score on two seven segment displays 00039 //wait(0.5); 00040 if(c == '1') 00041 Disp1=0xF9; 00042 if(c == '2') 00043 Disp1=0xA4; 00044 if(c == '3') 00045 Disp1=0xB0; 00046 if(c == '4') 00047 Disp1=0x99; 00048 if(c == '5') 00049 Disp1=0x92; 00050 if(c == '6') 00051 Disp1=0x82; 00052 if(c == '7') 00053 Disp1=0xF8; 00054 if(c == '8') 00055 Disp1=0x80; 00056 if(c == '9') 00057 Disp1=0x90; 00058 if(d== '0') 00059 Disp2=0xC0; 00060 //wait(0.5); 00061 if(d== '1') 00062 Disp2=0xF9; 00063 if(d == '2') 00064 Disp2=0xA4; 00065 if(d == '3') 00066 Disp2=0xB0; 00067 if(d == '4') 00068 Disp2=0x99; 00069 if(d == '5') 00070 Disp2=0x92; 00071 if(d == '6') 00072 Disp2=0x82; 00073 if(d == '7') 00074 Disp2=0xF8; 00075 if(d == '8') 00076 Disp2=0x80; 00077 if(d == '9') 00078 Disp2=0x90; 00079 00080 lcd.cls(); 00081 x=c-48; 00082 y=d-48; 00083 00084 lcd.printf("PLAYER-1... "); 00085 lcd.printf("%i \n",x); 00086 lcd.printf("PLAYER-2... "); 00087 lcd.printf("%i",y); 00088 00089 if((x>=9)||(y>=9)) 00090 { 00091 lcd.cls(); 00092 00093 if(x>y) 00094 { 00095 while(1){ 00096 lcd.printf("****CONGRATS****\n"); //Notification if a player wins over other. 00097 wait(0.5); 00098 lcd.cls(); 00099 lcd.printf("PLAYER-1 won by"); 00100 int z = x-y; 00101 lcd.printf("%i",z); 00102 lcd.printf("points"); 00103 wait(0.5); 00104 lcd.cls();} 00105 } 00106 if(x<y) 00107 { 00108 while(1){ 00109 lcd.printf("****CONGRATS****\n"); 00110 wait(0.5); 00111 lcd.cls(); 00112 lcd.printf("PLAYER-2 wins by"); 00113 int z = y-x; 00114 lcd.printf("%i ",z); 00115 lcd.printf("points"); 00116 wait(0.5); 00117 lcd.cls();} 00118 } 00119 if(x==y) 00120 { 00121 lcd.printf("!!!MATCH TIED!!!\n"); // condition when match is tied 00122 } 00123 } 00124 00125 wait(0.5); 00126 } 00127 } 00128
Generated on Mon Aug 1 2022 19:04:16 by
1.7.2
