Counter with LCD Display

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
bromand
Date:
Tue Jun 28 18:46:51 2011 +0000
Parent:
0:1abd7e24ae31
Commit message:
1.0.0.1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1abd7e24ae31 -r f580beec166a main.cpp
--- a/main.cpp	Tue Jun 28 15:10:44 2011 +0000
+++ b/main.cpp	Tue Jun 28 18:46:51 2011 +0000
@@ -6,120 +6,6 @@
 //Initialize TextLCD with the correct pins
 TextLCD lcd(p24, p26, p27, p28, p29, p30);
 
-//This function gets an integer and converts it to a charecter
-char* ConvertIntToChar(int i)
-{
-    char* c = "";
-    switch (i)
-    {
-    case 1:
-        c = "1";
-        break;
-    case 2:
-        c = "2";
-        break;
-    case 3:
-        c = "3";
-        break;
-    case 4:
-        c = "4";
-        break;
-    case 5:
-        c = "5";
-        break;
-    case 6:
-        c = "6";
-        break;
-    case 7:
-        c = "7";
-        break;
-    case 8:
-        c = "8";
-        break;
-    case 9:
-        c = "9";
-        break;
-    case 0:
-        c = "0";
-        break;
-    }
-    return c;
-}
-
-//Print to LCD function receives an integer as an input and print the number to the LCD display 
-//This function accepts values between 0 and 99999
-void PrintToLCD(int iCounter)
-{
-    //Check for out of range numbers
-    if (iCounter < 0 || iCounter > 99999)
-        return;
-        
-    char* c = "";
-    //case when the number is less than 10     
-    if(iCounter < 10)
-    {
-        c = ConvertIntToChar(iCounter);
-        lcd.locate(0, 1);
-        lcd.printf(c);
-    }
-    //case when the number is less than 100
-    else if (iCounter<100)
-    {
-        //devide the number by 10 to get the 10s
-        int i10s = iCounter/10;
-        c = ConvertIntToChar(i10s);
-        lcd.locate(0, 1);
-        lcd.printf(c);
-        //Get the leftover to print the 1s 
-        int i1s = iCounter%10; 
-        c = ConvertIntToChar(i1s);
-        lcd.locate(1, 1);
-        lcd.printf(c); 
-    }
-    else if (iCounter<1000)
-    {
-        //devide the number by 100 to get the 100s
-        int i100s = iCounter/100;
-        c = ConvertIntToChar(i100s);
-        lcd.locate(0, 1);
-        lcd.printf(c); 
-        //Get the leftover to compute the 10s and 1s
-        int iTemp = iCounter%100;
-        int i10s = iTemp/10;
-        c = ConvertIntToChar(i10s);
-        lcd.locate(1, 1);
-        lcd.printf(c);
-        int i1s = iTemp%10; 
-        c = ConvertIntToChar(i1s);
-        lcd.locate(2, 1);
-        lcd.printf(c); 
-    }
-    else if (iCounter<10000)
-    {
-        //devide the number by 1000 to get the 1000s
-        int i1000s = iCounter/1000;
-        c = ConvertIntToChar(i1000s);
-        lcd.locate(0, 1);
-        lcd.printf(c); 
-        //Get the leftover to compute the 100s, 10s and 1s
-        int iTemp100s = iCounter%1000;
-        int i100s = iTemp100s/100;
-        c = ConvertIntToChar(i100s);
-        lcd.locate(1, 1);
-        lcd.printf(c); 
-        //Get the leftover to compute the 10s and 1s
-        int iTemp10s = iTemp100s%100;
-        int i10s = iTemp10s/10;
-        c = ConvertIntToChar(i10s);
-        lcd.locate(2, 1);
-        lcd.printf(c);
-        int i1s = iTemp10s%10; 
-        c = ConvertIntToChar(i1s);
-        lcd.locate(3, 1);
-        lcd.printf(c); 
-    }          
-}
-
 //Main function
 int main() 
 { 
@@ -132,8 +18,10 @@
     //Iterate between 0 and 1000. 
     for(int i=0 ; i<=1000 ; i++)
     {
+        //Locate Row 1 Column 0 in the LCD display
+        lcd.locate(0, 1);
         //Call PrintToLCD function
-        PrintToLCD(i);
+        lcd.printf("%d", i);
         //wait for 250ms
         wait(0.25);
     }