Test program for creating a Dashboard display using the Nokia 5110 84x48 display module for a \'Greenpower\' endurance racing car. There are simple functions to generate the dashboard annotations and to update the instrument readouts
Dependencies: mbed N_5110_Display
main.cpp
00001 #include "mbed.h" 00002 #include "N_5110_Display.h" 00003 00004 // Test program for creating a Dashboard display using the Nokia 5110 84x48 display module for a 'Greenpower' endurance racing car. 00005 // There are simple functions to generate the dashboard annotations and to update the instrument readouts 00006 00007 N_5110_Display Display( p5, p6, p7, p8, p9, p10 ); 00008 00009 void doCarDash( void ); 00010 void speed( unsigned char value ); 00011 void gear( unsigned char value ); 00012 void bat( unsigned char value ); 00013 void temp( unsigned char value ); 00014 00015 //---------------------------------------------------------------------- 00016 00017 void doCarDash( void ) 00018 // generate the Dashboard layout annotations 00019 { 00020 Display.setCharPos( 0, 0 ); 00021 Display.printString( "V+", 1, 1 ); 00022 Display.setCharPos( 12, 0 ); 00023 Display.printString( "~C", 1, 1 ); 00024 Display.setCharPos( 4, 0 ); 00025 Display.printString( "MPH", 2, 1 ); 00026 Display.setCharPos( 0, 5 ); 00027 Display.printString( "Gear-> <-Auto", 1, 1 ); 00028 Display.setCharPos( 2, 1 ); 00029 Display.print1char( 'F', 1, 1 ); 00030 Display.setCharPos( 2, 2 ); 00031 Display.print1char( '_', 1, 1 ); 00032 Display.setCharPos( 2, 4 ); 00033 Display.print1char( 'E', 1, 1 ); 00034 Display.setCharPos( 11, 1 ); 00035 Display.print1char( 'H', 1, 1 ); 00036 Display.setCharPos( 11, 2 ); 00037 Display.print1char( '_', 1, 1 ); 00038 Display.setCharPos( 11, 4 ); 00039 Display.print1char( 'C', 1, 1 ); 00040 } 00041 00042 //---------------------------------------------------------------------- 00043 00044 void speed( unsigned char value ) 00045 { 00046 unsigned char tens, units; 00047 00048 tens = value / 10; 00049 units = value % 10; 00050 00051 if (tens == 0) //if tens is zero then use blank 00052 { 00053 tens = ' '; 00054 } 00055 else 00056 { 00057 tens = tens + 0x30; //otherwise convert to ASCII 00058 } 00059 00060 if (units == 0) //if units zero then use capital O 00061 { 00062 units = 'O'; 00063 } 00064 else 00065 { 00066 units = units + 0x30; //otherwise convert to ASCII 00067 } 00068 00069 Display.setCharPos( 4, 1 ); //update the Speed display 00070 Display.print1char( tens, 3, 4 ); 00071 Display.print1char( units, 3, 4 ); 00072 } 00073 00074 void gear( unsigned char value ) 00075 { 00076 Display.setCharPos( 6, 5 ); //Gear display position 00077 00078 if (value == 0) 00079 { 00080 Display.print1char( 'N', 2, 1 ); //if gear zero then use 'N' for neutral 00081 } 00082 else if (value > 0 && value < 10) 00083 { 00084 Display.print1char( value+0x30, 2, 1 ); //otherwise convert to ASCII 00085 } 00086 else 00087 { 00088 Display.print1char( 'E', 2, 1 ); //if Gear value greater than 9 (Out of range) then display 'E' for Error 00089 } 00090 } 00091 00092 void bat( unsigned char percent ) 00093 { 00094 Display.setCharPos( 0, 1 ); //Left Bar Grapf (Bat) 00095 Display.VertBarGraph( percent, 2, 4 ); 00096 } 00097 00098 void temp( unsigned char percent ) 00099 { 00100 Display.setCharPos( 12, 1 ); //Right Bar Graph (Temp) 00101 Display.VertBarGraph( percent, 2, 4 ); 00102 } 00103 00104 //--------------------------------------------------------------------- 00105 00106 int main() 00107 { 00108 unsigned char count; 00109 00110 doCarDash(); 00111 00112 for (count=0; count<43; count++) 00113 { 00114 temp( count ); 00115 speed( count ); 00116 bat( 99 - count ); 00117 gear( count/11+1 ); 00118 00119 wait(0.5); 00120 } 00121 }
Generated on Thu Jul 28 2022 17:09:53 by
1.7.2
Pete Isley