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
Revision 1:d2516338d922, committed 2013-10-27
- Comitter:
- sumitpuneet
- Date:
- Sun Oct 27 19:12:39 2013 +0000
- Parent:
- 0:0d7325bb3025
- Commit message:
- display system for Air Hockey
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 23 06:00:16 2013 +0000 +++ b/main.cpp Sun Oct 27 19:12:39 2013 +0000 @@ -1,53 +1,128 @@ // Hello World! for the TextLCD #include "mbed.h" -#include "TextLCD.h" +#include "TextLCD.h" //header file to interact with LCD 16*2 + + +BusOut Disp2(p21,p22,p23,p24,p25,p26,p27,p5);//a.b.c.d.e.f.g.dp +BusOut Disp1(p28,p29,p30,p33,p34,p35,p36,p5);//a.b.c.d.e.f.g.dp +Serial pc(USBTX, USBRX); // tx, rx TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 -int x=9; -int y=9; int z; -int main() { +int x=0; +int y=0; +int main() +{ pc.baud(9600); //fixing the baud rate of transmission to 9600 bits. - lcd.printf("PLAYER-1..."); - lcd.printf("%i\n",x); - lcd.printf("PLAYER-2..."); - lcd.printf("%i",y); - if((x>=9)||(y>=9)) - { - lcd.cls(); - - if(x>y) + Disp1=0xC0; //setting the initial displays of seven segment to zero + Disp2=0xC0; + + + lcd.cls(); //clear screen function for lcd + lcd.printf("** WELCOME **"); //initially printing on LCD + wait(2); // 2 second waiting time before proceeding further + lcd.cls(); + lcd.printf("PLAYER-1... "); + lcd.printf("%i \n",x); //fetching current player 1 score + lcd.printf("PLAYER-2... "); + lcd.printf("%i",y);//fetching current player 2 score + + while(1) { - while(1){ - lcd.printf("****CONGRATS****\n"); - wait(0.5); - lcd.cls(); - lcd.printf("PLAYER-1 won by"); - int z = x-y; - lcd.printf("%i",z); - lcd.printf("points"); - wait(0.5); - lcd.cls();} - } + char c = pc.getc(); //get character serially + char d = pc.getc(); + pc.printf("%c",c); + pc.printf("%c",c); + if(c == '0') + Disp1=0xC0; //display fetched Score on two seven segment displays + //wait(0.5); + if(c == '1') + Disp1=0xF9; + if(c == '2') + Disp1=0xA4; + if(c == '3') + Disp1=0xB0; + if(c == '4') + Disp1=0x99; + if(c == '5') + Disp1=0x92; + if(c == '6') + Disp1=0x82; + if(c == '7') + Disp1=0xF8; + if(c == '8') + Disp1=0x80; + if(c == '9') + Disp1=0x90; + if(d== '0') + Disp2=0xC0; + //wait(0.5); + if(d== '1') + Disp2=0xF9; + if(d == '2') + Disp2=0xA4; + if(d == '3') + Disp2=0xB0; + if(d == '4') + Disp2=0x99; + if(d == '5') + Disp2=0x92; + if(d == '6') + Disp2=0x82; + if(d == '7') + Disp2=0xF8; + if(d == '8') + Disp2=0x80; + if(d == '9') + Disp2=0x90; + + lcd.cls(); + x=c-48; + y=d-48; + + lcd.printf("PLAYER-1... "); + lcd.printf("%i \n",x); + lcd.printf("PLAYER-2... "); + lcd.printf("%i",y); + + if((x>=9)||(y>=9)) + { + lcd.cls(); + + if(x>y) + { + while(1){ + lcd.printf("****CONGRATS****\n"); //Notification if a player wins over other. + wait(0.5); + lcd.cls(); + lcd.printf("PLAYER-1 won by"); + int z = x-y; + lcd.printf("%i",z); + lcd.printf("points"); + wait(0.5); + lcd.cls();} + } if(x<y) - { - while(1){ - lcd.printf("****CONGRATS****\n"); - wait(0.5); - lcd.cls(); - lcd.printf("PLAYER-2 wins by"); - int z = y-x; - lcd.printf("%i",z); - lcd.printf("points"); - wait(0.5); - lcd.cls();} - } + { + while(1){ + lcd.printf("****CONGRATS****\n"); + wait(0.5); + lcd.cls(); + lcd.printf("PLAYER-2 wins by"); + int z = y-x; + lcd.printf("%i ",z); + lcd.printf("points"); + wait(0.5); + lcd.cls();} + } if(x==y) - { - lcd.printf("MATCH TIED\n"); - } -} - - } + { + lcd.printf("!!!MATCH TIED!!!\n"); // condition when match is tied + } + } + + wait(0.5); + } + } \ No newline at end of file