displays a float (decimal number) to 4 digit, 7 segment LED display LDQ-N514R1 using mbed LPC1768

Dependencies:   mbed

Fork of 7SegmentDisplay by Svend Kaffke

Files at this revision

API Documentation at this revision

Comitter:
captaintim
Date:
Sun Sep 04 11:54:00 2016 +0000
Parent:
1:46dbd77e0701
Child:
3:c747b832518f
Commit message:
displays decimal number to a 4 digit, 7segment display (LDQ-N514R1), reveal how to finesse digits out one at a time for display, and flash display fast enough to show decimal number

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Sep 03 17:36:47 2016 +0000
+++ b/main.cpp	Sun Sep 04 11:54:00 2016 +0000
@@ -26,8 +26,10 @@
 G               5          27
 
 There is no blanking on this display, 
+Program demonstrates writing to all four digits of the 7-segment LED display of the LDQ-N514R1 a decimal number
+Since the segments only light up for one selected digit, all 4 digit has to be flashed to show 4 separate numbers
+Television used this by flashing 30 screens per second call persistence enhanced cathode ray tubes.
 
-Program demonstrates writing to one 7-segment display of 4 digit display LDQ-N514R1  
 Author: Cap'n Tim Johnson PE
 Retired Professor
 Wentworth Institude of Technology 
@@ -40,6 +42,7 @@
 DigitalOut Digit2(p13);
 DigitalOut Digit3(p12);
 DigitalOut Digit4(p11);
+DigitalOut myled (LED1);  //Signal used for runtime checking
 
 //these are the pins associated with writing to the "led"
 DigitalOut led[8]={p21, p22, p23, p24, p25, p26, p27, p10};
@@ -60,33 +63,88 @@
                     {0,0,0,0,0,0,0,1}          //dot
                   };
 
+//create matrix to handle decimal point
+int matrixdecimal[11][8]={
+                    {1,1,1,1,1,1,0,1},          //zero
+                    {0,1,1,0,0,0,0,1},          //one
+                    {1,1,0,1,1,0,1,1},          //two
+                    {1,1,1,1,0,0,1,1},          //three
+                    {0,1,1,0,0,1,1,1},          //four
+                    {1,0,1,1,0,1,1,1},          //five
+                    {1,0,1,1,1,1,1,1},          //six
+                    {1,1,1,0,0,0,0,1},          //seven
+                    {1,1,1,1,1,1,1,1},          //eight
+                    {1,1,1,0,0,1,1,1},          //nine
+                    {0,0,0,0,0,0,0,1}          //dot...actually a leading null space
+                  };
 
-int main() {
-    //DigitalOut (p14, 0); //Turn on digit#1, Most Significant Digit
-   
+//set persistance (wait value on digits or flash rate)
+float f = 0.005;
+//enter a float number here (with a decimal in it) starting point
+volatile float temp = 31.45;
+
+int main(){
+//finessing the digits out one at a time knowing 2nd digit has the decimal
+int tempasinteger = temp * 100;  //removes decimal and typecasts float to integer
+int temp1a=tempasinteger/1000;    //typecast float to integer for 1st digit (was)
+int temp2 = tempasinteger - temp1a*1000;  //gets last 3 digits
+int temp2a = temp2/100;   //typecast float to integer for 2nd digit
+int temp3 = temp2 - temp2a*100;  //get last 2 digits
+
+int temp3a=temp3/10;    //typecast float to integer for 3rd digit 
+int temp4=temp3-temp3a*10;   //gets last digit  
+int temp4a = temp4;     //convenient renaming for writing digit to display
+
+//begin one write of the display by turning off all the digits    
     Digit1 = 1; //turn off digit1
     Digit2 = 1; //turn off digit2
     Digit3 = 1; //turn off digit3
     Digit4 = 1; //turn off digit4
-
-    while (1) {
-            //Digit1 = 0; //turn on digit1    
-            //all led's off
+    while (1) {       
+        //turns off last led's segments values
         for(int i = 0; i<8;i++){
-            led[i] = 0;
-            }
+            led[i] = 0;}
+         //belows holds row of matrix and assign column value from matrix
+         Digit1 = 0;             //turns on digit1
+            for (int i=0; i<8; i++){
+                led[i] = matrix[temp1a][i];
+                }  
+        wait(f);
+        Digit1=1;
         
-        //belows holds row of matrix and assign column value from matrix
-        for (int d=0; d<11; d++){
-            Digit1 = 0;             //turns on digit1
+     //turns off last led's segments values
+        for(int i = 0; i<8;i++){
+            led[i] = 0;}
+         //belows holds row of matrix and assign column value from matrix
+         Digit2 = 0;             //turns on digit2 with decimal
             for (int i=0; i<8; i++){
-                led[i] = matrix[d][i];
-                }  
-            wait(0.5);
-            Digit1 = 1; //turn off digit1
-            wait(1);
-       }
-        wait(1);
-    
-    }
+                //since we have prior knowledge of the decimal location 
+                //and this is a demonstration program, we add the decimal for this digit
+                led[i] = matrixdecimal[temp2a][i];
+                } 
+        wait(f);
+        Digit2=1;
+                    
+     //turns off last led's segments values
+        for(int i = 0; i<8;i++){
+            led[i] = 0;}
+         //belows holds row of matrix and assign column value from matrix
+         Digit3 = 0;             //turns on digit3
+            for (int i=0; i<8; i++){
+                led[i] = matrix[temp3a][i];
+                }             
+        wait(f);
+        Digit3=1;
+        
+             //turns off last led's segments values
+        for(int i = 0; i<8;i++){
+            led[i] = 0;}
+         //belows holds row of matrix and assign column value from matrix
+         Digit4 = 0;             //turns on digit4
+            for (int i=0; i<8; i++){
+                led[i] = matrix[temp4a][i];                }  
+        wait(f);
+        Digit4=1;
+        
+      }
 }
\ No newline at end of file