Integration with potentiometer

Dependencies:   BSP_DISCO_F469NI LCD_DISCO_F469NI SD_DISCO_F469NI mbed

Committer:
formulas
Date:
Thu Dec 07 16:53:40 2017 +0000
Revision:
0:e53b0806a628
Integration with potentiometer;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
formulas 0:e53b0806a628 1 #include "mbed.h"
formulas 0:e53b0806a628 2 #include "functions.h"
formulas 0:e53b0806a628 3
formulas 0:e53b0806a628 4 LCD_DISCO_F469NI lcd;
formulas 0:e53b0806a628 5 SD_DISCO_F469NI sd;
formulas 0:e53b0806a628 6 Serial pc(USBTX, USBRX);
formulas 0:e53b0806a628 7 AnalogIn speed_value(A0);
formulas 0:e53b0806a628 8 DigitalIn changescreen_command(D0);
formulas 0:e53b0806a628 9 DigitalIn brake(D1);
formulas 0:e53b0806a628 10
formulas 0:e53b0806a628 11 float Vin;
formulas 0:e53b0806a628 12 extern GEAR *Gears;
formulas 0:e53b0806a628 13 extern IMAGE LogoBig,LogoSmall,Branko;
formulas 0:e53b0806a628 14
formulas 0:e53b0806a628 15 void MainScreen();
formulas 0:e53b0806a628 16 void FirstAuxScreen();
formulas 0:e53b0806a628 17 void SecondAuxScreen();
formulas 0:e53b0806a628 18
formulas 0:e53b0806a628 19 int main(){
formulas 0:e53b0806a628 20 DrawRGBImage(LogoBig,0,0);
formulas 0:e53b0806a628 21 wait(0.5);
formulas 0:e53b0806a628 22 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:e53b0806a628 23 lcd.FillRect(0,0,800,480);
formulas 0:e53b0806a628 24 MainScreen();
formulas 0:e53b0806a628 25 };
formulas 0:e53b0806a628 26
formulas 0:e53b0806a628 27
formulas 0:e53b0806a628 28 void MainScreen(){
formulas 0:e53b0806a628 29 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 30 DrawSpeedMeter();
formulas 0:e53b0806a628 31 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:e53b0806a628 32 lcd.SetFont(&Font24);
formulas 0:e53b0806a628 33 lcd.DisplayStringAt(30,170,(uint8_t*)"Oil Temp",LEFT_MODE);
formulas 0:e53b0806a628 34 lcd.DisplayStringAt(30,320,(uint8_t*)"Water Temp",LEFT_MODE);
formulas 0:e53b0806a628 35 lcd.DisplayStringAt(584,170,(uint8_t*)"TPS",LEFT_MODE);
formulas 0:e53b0806a628 36 lcd.SetTextColor(LCD_COLOR_DARKRED);
formulas 0:e53b0806a628 37 lcd.FillRect(560,340,230,68);
formulas 0:e53b0806a628 38 lcd.SetBackColor(LCD_COLOR_DARKRED);
formulas 0:e53b0806a628 39 PrintString("BRAKE",50,575,350,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 40 lcd.SetBackColor(LCD_COLOR_WHITE);
formulas 0:e53b0806a628 41 uint8_t V0=0;
formulas 0:e53b0806a628 42 int gear=1;
formulas 0:e53b0806a628 43 int brake0;
formulas 0:e53b0806a628 44 while(changescreen_command.read()==0){
formulas 0:e53b0806a628 45 Vin=(int)(speed_value.read()*150);
formulas 0:e53b0806a628 46 UpdateSpeedMeter(V0,Vin-V0);
formulas 0:e53b0806a628 47 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 48 ChangeNumber(Vin,V0,100,OilTempXPos,OilTempYPos);
formulas 0:e53b0806a628 49 ChangeNumber(Vin,V0,100,WaterTempXPos,WaterTempYPos);
formulas 0:e53b0806a628 50 ChangeNumber(Vin,V0,100,TPSXPos,TPSYPos);
formulas 0:e53b0806a628 51 BrakeSignal(brake.read(),brake0);
formulas 0:e53b0806a628 52 V0=Vin;
formulas 0:e53b0806a628 53 brake0=brake;
formulas 0:e53b0806a628 54 if (Vin==0 & gear!=0){
formulas 0:e53b0806a628 55 PrintChar(Gears[0],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 56 gear=0;
formulas 0:e53b0806a628 57 } else if (Vin>0 & Vin<=20 & gear!=1){
formulas 0:e53b0806a628 58 PrintChar(Gears[1],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 59 gear=1;
formulas 0:e53b0806a628 60 } else if (Vin>20 & Vin<=40 & gear!=2){
formulas 0:e53b0806a628 61 PrintChar(Gears[2],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 62 gear=2;
formulas 0:e53b0806a628 63 } else if (Vin>40 & Vin<=60 & gear!=3){
formulas 0:e53b0806a628 64 PrintChar(Gears[3],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 65 gear=3;
formulas 0:e53b0806a628 66 } else if (Vin>60 & Vin<=80 & gear!=4){
formulas 0:e53b0806a628 67 PrintChar(Gears[4],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 68 gear=4;
formulas 0:e53b0806a628 69 } else if (Vin>80 & Vin<=100 & gear!=5){
formulas 0:e53b0806a628 70 PrintChar(Gears[5],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 71 gear=5;
formulas 0:e53b0806a628 72 } else if (Vin>100 & gear!=6){
formulas 0:e53b0806a628 73 PrintChar(Gears[6],GearXPos,GearYPos,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 74 gear=6;
formulas 0:e53b0806a628 75 };
formulas 0:e53b0806a628 76 };
formulas 0:e53b0806a628 77 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:e53b0806a628 78 lcd.FillRect(0,0,800,480);
formulas 0:e53b0806a628 79 FirstAuxScreen();
formulas 0:e53b0806a628 80 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 81 };
formulas 0:e53b0806a628 82
formulas 0:e53b0806a628 83 void FirstAuxScreen(){
formulas 0:e53b0806a628 84 PrintString("Oil P",50,20,25,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 85 PrintString("MAP",50,20,100,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 86 PrintString("Air Temp",50,20,175,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 87 PrintString("Lambda",50,20,250,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 88 PrintString("Volts",50,20,325,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 89 PrintString("Crank",50,20,400,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 90 PrintString("kPa",50,470,25,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 91 PrintString("kPa",50,470,100,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 92 PrintString("C",50,470,175,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 93 PrintString("Ratio",50,470,250,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 94 PrintString("V",50,470,325,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 95 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:e53b0806a628 96 int V0=0;
formulas 0:e53b0806a628 97 while(changescreen_command.read()==0){
formulas 0:e53b0806a628 98 Vin=(int)(speed_value.read()*150);
formulas 0:e53b0806a628 99 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 100 ChangeNumber(Vin,V0,50,OilPXPos,OilPYPos);
formulas 0:e53b0806a628 101 ChangeNumber(Vin,V0,50,MAPXPos,MAPYPos);
formulas 0:e53b0806a628 102 ChangeNumber(Vin,V0,50,AirTempXPos,AirTempYPos);
formulas 0:e53b0806a628 103 ChangeNumber(Vin,V0,50,LambdaXPos,LambdaYPos);
formulas 0:e53b0806a628 104 ChangeNumber(Vin,V0,50,VoltsXpos,VoltsYPos);
formulas 0:e53b0806a628 105 if (Vin>100){
formulas 0:e53b0806a628 106 PrintString("ERROR",50,CrankXPos,CrankYPos,LCD_COLOR_RED);
formulas 0:e53b0806a628 107 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 108 } else {
formulas 0:e53b0806a628 109 PrintString(" ",50,350,400,LCD_COLOR_GREEN);
formulas 0:e53b0806a628 110 PrintString("OK",50,CrankXPos,CrankYPos,LCD_COLOR_GREEN);
formulas 0:e53b0806a628 111 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 112 };
formulas 0:e53b0806a628 113 V0=Vin;
formulas 0:e53b0806a628 114 };
formulas 0:e53b0806a628 115 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:e53b0806a628 116 lcd.FillRect(0,0,800,480);
formulas 0:e53b0806a628 117 SecondAuxScreen();
formulas 0:e53b0806a628 118
formulas 0:e53b0806a628 119 };
formulas 0:e53b0806a628 120
formulas 0:e53b0806a628 121 void SecondAuxScreen(){
formulas 0:e53b0806a628 122 PrintString("LVDT Sensors",50,200,20,LCD_COLOR_BLACK);
formulas 0:e53b0806a628 123 DrawRGBImage(LogoSmall,LogoSmallXPos,LogoSmallYPos);
formulas 0:e53b0806a628 124 int V0=0;
formulas 0:e53b0806a628 125 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 126 lcd.SetFont(&Font24);
formulas 0:e53b0806a628 127 lcd.DisplayStringAt(FLLVDTBarXPos+25,FLLVDTBarYPos,(uint8_t*)"FL",LEFT_MODE);
formulas 0:e53b0806a628 128 lcd.DisplayStringAt(FRLVDTBarXPos+25,FRLVDTBarYPos,(uint8_t*)"FR",LEFT_MODE);
formulas 0:e53b0806a628 129 lcd.DisplayStringAt(BLLVDTBarXPos+25,BLLVDTBarYPos,(uint8_t*)"BL",LEFT_MODE);
formulas 0:e53b0806a628 130 lcd.DisplayStringAt(BRLVDTBarXPos+25,BRLVDTBarYPos,(uint8_t*)"BR",LEFT_MODE);
formulas 0:e53b0806a628 131
formulas 0:e53b0806a628 132 while(changescreen_command.read()==0){
formulas 0:e53b0806a628 133 Vin=(int)(speed_value.read()*150);
formulas 0:e53b0806a628 134 ChangeNumber(Vin,V0,100,FLLVDTXPos,FLLVDTYPos);
formulas 0:e53b0806a628 135 ChangeNumber(Vin,V0,100,FRLVDTXPos,FRLVDTYPos);
formulas 0:e53b0806a628 136 ChangeNumber(Vin,V0,100,BLLVDTXPos,BLLVDTYPos);
formulas 0:e53b0806a628 137 ChangeNumber(Vin,V0,100,BRLVDTXPos,BRLVDTYPos);
formulas 0:e53b0806a628 138 UpdateLVDTScale(Vin,V0,FLLVDTBarXPos,FLLVDTBarYPos);
formulas 0:e53b0806a628 139 UpdateLVDTScale(Vin,V0,FRLVDTBarXPos,FRLVDTBarYPos);
formulas 0:e53b0806a628 140 UpdateLVDTScale(Vin,V0,BLLVDTBarXPos,BLLVDTBarYPos);
formulas 0:e53b0806a628 141 UpdateLVDTScale(Vin,V0,BRLVDTBarXPos,BRLVDTBarYPos);
formulas 0:e53b0806a628 142 V0=Vin;
formulas 0:e53b0806a628 143 };
formulas 0:e53b0806a628 144 lcd.SetTextColor(LCD_COLOR_WHITE);
formulas 0:e53b0806a628 145 lcd.FillRect(0,0,800,480);
formulas 0:e53b0806a628 146 lcd.SetTextColor(LCD_COLOR_BLACK);
formulas 0:e53b0806a628 147 MainScreen();
formulas 0:e53b0806a628 148 };