display system for Air Hockey

Dependencies:   TextLCD mbed

Fork of congolcd by Akash Dwivedi

main.cpp

Committer:
sumitpuneet
Date:
2013-10-27
Revision:
1:d2516338d922
Parent:
0:0d7325bb3025

File content as of revision 1:d2516338d922:

// Hello World! for the TextLCD

#include "mbed.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 z;
int x=0;
int y=0;
int main() 
{      pc.baud(9600); //fixing the baud rate of transmission to 9600 bits.

        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)         
       {
            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();}
             }
       if(x==y)
            {
       lcd.printf("!!!MATCH TIED!!!\n");  // condition when match is tied
            }
        }
        
        wait(0.5);
        }
        }