Al Husien Dabashi / Mbed 2 deprecated 1620_Project_Template

Dependencies:   N5110 ShiftReg Tone mbed

Fork of 1620_Project_Template by Craig Evans

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ModeD.cpp Source File

ModeD.cpp

00001 #include "ModeD.h"
00002 
00003 void mode_D()
00004 {
00005     lcd.clear();
00006     lcd.printString("Mode D",0,0);
00007     lcd.refresh();
00008     wait_ms(250);
00009 
00010     AnalogIn  joy_v(p20);
00011     AnalogIn  joy_h(p19);
00012 
00013     shift.write(0x3f);
00014 
00015     float gear_ratio;
00016     float speed;
00017     float RPM;
00018 
00019     while (button_d.read() == 0) {
00020         // code goes in here - this acts like the main while(1) loop
00021 
00022         lcd.clear();
00023         lcd.printString("Mode D",0,0);
00024         lcd.printString("0",2,17);
00025 
00026         float pot2_val = pot_2.read();
00027         RPM = pot2_val*5300+700;
00028 
00029         char RPM_val[27];
00030         sprintf(RPM_val,"%.0f",RPM);
00031         lcd.printString(RPM_val,25,2);
00032 
00033         lcd.drawRect(5,8,74,7,FILL_TRANSPARENT); // RPM bar
00034         lcd.drawRect(5,30,74,7,FILL_TRANSPARENT); // Speed bar
00035 
00036         float pot2_acc = pot_2.read();
00037         lcd.drawRect(6,9,pot2_val*74,6,FILL_BLACK);
00038 
00039         lcd.printString("0",3,5);
00040         lcd.printString("137",65,5);
00041         lcd.printString("0",3,2);
00042         lcd.printString("6000",60,2);
00043 
00044         float xr = joy_h.read();
00045         float yr = joy_v.read();
00046         
00047         if (button_a.read() == 1) {
00048 
00049             if((xr<0.2)&& (yr<0.2)) {
00050                 shift.write(0x31);
00051                 gear_ratio=3.62;
00052             } else if((0.8<xr)&& (0.8<yr)) {
00053                 shift.write(0x06);
00054                 gear_ratio=3.85;
00055             } else if((0.8<xr)&& (yr<0.2)) {
00056                 shift.write(0x5B);
00057                 gear_ratio=2.04;
00058             } else if((0.4<xr)&& (xr<0.6)&& (0.8<yr)) {
00059                 shift.write(0x4F);
00060                 gear_ratio=1.28;
00061             } else if((0.4<xr)&&(xr<0.6)&& (yr<0.2)) {
00062                 shift.write(0x66);
00063                 gear_ratio=0.95;
00064             } else if((xr<0.2)&& (0.8<yr)) {
00065                 shift.write(0x6D);
00066                 gear_ratio=0.76;
00067             } else {
00068                 shift.write(0x3f);
00069                 gear_ratio=1000000000;
00070             }
00071             
00072         }
00073 
00074         speed=(0.001174392*RPM*60)/(gear_ratio*4.07);
00075         printf("RPM = %1.0f  speed = %.0f mph\n",RPM,speed);
00076 
00077         lcd.drawRect(5,30,speed*37/68,7,FILL_BLACK);
00078         
00079         char speed_val[27];
00080         sprintf(speed_val,"%.0f",speed);
00081         lcd.printString(speed_val,27,5);
00082 
00083         lcd.refresh();
00084         wait_ms(100);
00085     }
00086 
00087 }