automotive simulation thingy
Dependencies: N5110 ShiftReg Tone mbed
Fork of 1620_Project_Template by
Revision 2:e7e39d27b11f, committed 2017-06-29
- Comitter:
- Al_Husien_Dabashi
- Date:
- Thu Jun 29 22:41:30 2017 +0000
- Parent:
- 1:76241e21ec61
- Commit message:
- 1620 Final Automotive simulation
Changed in this revision
diff -r 76241e21ec61 -r e7e39d27b11f Main/main.cpp --- a/Main/main.cpp Mon Mar 13 07:01:51 2017 +0000 +++ b/Main/main.cpp Thu Jun 29 22:41:30 2017 +0000 @@ -6,6 +6,8 @@ DigitalIn button_c(p27); DigitalIn button_d(p26); + + N5110 lcd(p8,p9,p10,p11,p13,p21); BusOut leds(LED4,LED3,LED2,LED1); @@ -24,6 +26,7 @@ Tone speaker(p18); ShiftReg shift; + int main() { init(); // initialise peripherals @@ -50,7 +53,7 @@ // delay to prevent multiple button presses being detected wait_ms(250); - } + }lcd.clear(); } void init() @@ -91,8 +94,9 @@ lcd.printString(" Automotive",0,0); lcd.printString(" Electronics",0,1); lcd.printString(" Simulator",0,2); - lcd.printString("Craig A. Evans",0,4); - lcd.printString(" 0123456789",0,5); + lcd.printString(" Al Husien",0,3); + lcd.printString(" Dabashi",0,4); + lcd.printString(" 201042563",0,5); lcd.refresh(); wait(5.0); } \ No newline at end of file
diff -r 76241e21ec61 -r e7e39d27b11f ModeA/ModeA.cpp --- a/ModeA/ModeA.cpp Mon Mar 13 07:01:51 2017 +0000 +++ b/ModeA/ModeA.cpp Thu Jun 29 22:41:30 2017 +0000 @@ -1,17 +1,96 @@ #include "ModeA.h" -void mode_A() { - +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +void mode_A() +{ + lcd.clear(); + + lcd.printString("Mode A",0,0); lcd.refresh(); wait_ms(250); // small delay to prevent previous press being detected again - while (button_a.read() == 0) { - - // code goes in here - this acts like the main while(1) loop - + while (button_a.read() == 0) { // code goes in here - this acts like the main while(1) loop + + lcd.clear(); + + lcd.printString("Mode A",0,0); + + int petrol[12][11] = { + { 0,0,1,1,1,1,1,0,0,0,0 }, + { 0,0,1,0,0,0,1,0,0,1,1 }, + { 0,0,1,0,0,0,1,0,0,1,1 }, + { 0,0,1,0,0,0,1,0,0,0,1 }, + { 0,0,1,0,0,0,1,0,0,1,0 }, + { 0,0,1,1,1,1,1,0,0,1,0 }, + { 0,0,1,1,1,1,1,0,1,0,0 }, + { 0,0,1,1,1,1,1,0,1,0,0 }, + { 0,0,1,1,1,1,1,1,0,0,0 }, + { 0,0,1,1,1,1,1,0,0,0,0 }, + { 1,1,1,1,1,1,1,1,1,0,0 }, + { 1,1,1,1,1,1,1,1,1,0,0 }, + }; + lcd.drawSprite(3,10,12,11,(int *)petrol); + int temp[19][3] = { + { 0,1,0}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 1,0,1}, + { 0,1,0}, + { 1,1,1}, + { 1,1,1}, + { 1,0,1}, + { 1,1,1}, + }; + lcd.drawSprite(6,27,19,3,(int *)temp); + + float pot0_val = pot_0.read(); + float pot1_val = pot_1.read(); + + lcd.drawRect(16,10,68,12,FILL_TRANSPARENT); // Fuel Bar + lcd.drawRect(16,30,68,12,FILL_TRANSPARENT); // Temperature Bar + + float W1=pot0_val*67; + float W2=(pot1_val*67); + + lcd.drawRect(17,11,W1,10,FILL_BLACK); + lcd.drawRect(17,31,W2,10,FILL_BLACK); + + float Fuel_lvl=pot0_val*100; + float Engine_temp=(pot1_val*80)+50; + printf("Fuel level = %.02f%% Engine temperature = %.02f Degrees C\n", Fuel_lvl, Engine_temp); + + if (Fuel_lvl<20) { + myled4=1; + } else { + myled4=0; + } + + if (Engine_temp>110) { + myled1=1; + } else { + myled1=0; + } + + + lcd.refresh(); + wait_ms(100); } } \ No newline at end of file
diff -r 76241e21ec61 -r e7e39d27b11f ModeB/ModeB.cpp --- a/ModeB/ModeB.cpp Mon Mar 13 07:01:51 2017 +0000 +++ b/ModeB/ModeB.cpp Thu Jun 29 22:41:30 2017 +0000 @@ -1,5 +1,10 @@ #include "ModeB.h" +DigitalOut myled11(LED1); +DigitalOut myled22(LED2); +DigitalOut myled33(LED3); +DigitalOut myled44(LED4); + void mode_B() { @@ -9,10 +14,70 @@ wait_ms(250); while (button_b.read() == 0) { + // code goes in here - this acts like the main while(1) loop - // code goes in here - this acts like the main while(1) loop + lcd.clear(); + + float pot0_hbl = pot_0.read(); + + if (pot0_hbl>0.2) { + myled11=1; + } else { + myled11=0; + } + if (pot0_hbl>0.4) { + myled22=1; + } else { + myled22=0; + } + if (pot0_hbl>0.6) { + myled33=1; + } else { + myled33=0; + } + if (pot0_hbl>0.8) { + myled44=1; + } else { + myled44=0; + } - } + if (pot0_hbl<0.2) { + printf("Heater set to level 0"); + } else if (0.8<pot0_hbl) { + printf("Heater set to level 4"); + } else if (0.6<pot0_hbl) { + printf("Heater set to level 3"); + } else if (0.4<pot0_hbl) { + printf("Heater set to level 2"); + } else { + printf("Heater set to level 1"); + } + + lcd.printString("Mode B",0,0); + lcd.printString("Cabin temp",0,2); -} \ No newline at end of file + float Temp = tmp36.read(); + float temperature = 100.0f*3.3f*Temp - 50.0f; + printf(" Cabin temperature= %0.2f C\n",temperature); + + char temp_val[27]; + sprintf(temp_val,"%.2f C",temperature); + lcd.printString(temp_val,0,3); + + + float value = ldr.read(); + if (value>0.5f) { + blue_led.write(0); + red_led.write(0); + green_led.write(0); + } else { + blue_led.write(1); + red_led.write(1); + green_led.write(1); + } + + lcd.refresh(); + wait_ms(100); + } +}
diff -r 76241e21ec61 -r e7e39d27b11f ModeC/ModeC.cpp --- a/ModeC/ModeC.cpp Mon Mar 13 07:01:51 2017 +0000 +++ b/ModeC/ModeC.cpp Thu Jun 29 22:41:30 2017 +0000 @@ -9,10 +9,51 @@ wait_ms(250); // small delay to prevent previous press being detected again while (button_c.read() == 0) { - // code goes in here - this acts like the main while(1) loop + lcd.clear(); + lcd.printString("Mode C",0,0); + + float pot0_val1 = pot_0.read(); + float dist_cm = pot0_val1*200; + printf("Gap distance = %.0f cm\n",dist_cm); + + speaker.init(); + + float t = dist_cm*19/4000+0.05; + speaker.play(1000,t); + // printf("%0.2f\n",t); + + + float W1=pot0_val1*-75+75; + lcd.drawRect(3,27,75,12,FILL_TRANSPARENT); + lcd.drawRect(3,27,W1,12,FILL_BLACK); + + if (dist_cm<20) { + blue_led.write(1); + red_led.write(0); + green_led.write(1); + } else { + blue_led.write(1); + red_led.write(1); + green_led.write(1); + } + + + int arrow[5][20] = { + { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 }, + { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 }, + { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, + { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 }, + { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 }, + }; + lcd.drawSprite(30,20,5,20,(int *)arrow); + + + + lcd.refresh(); + wait(t); } } \ No newline at end of file
diff -r 76241e21ec61 -r e7e39d27b11f ModeD/ModeD.cpp --- a/ModeD/ModeD.cpp Mon Mar 13 07:01:51 2017 +0000 +++ b/ModeD/ModeD.cpp Thu Jun 29 22:41:30 2017 +0000 @@ -1,17 +1,87 @@ #include "ModeD.h" -void mode_D() { - +void mode_D() +{ lcd.clear(); lcd.printString("Mode D",0,0); lcd.refresh(); wait_ms(250); + AnalogIn joy_v(p20); + AnalogIn joy_h(p19); + + shift.write(0x3f); + + float gear_ratio; + float speed; + float RPM; + while (button_d.read() == 0) { - // code goes in here - this acts like the main while(1) loop + lcd.clear(); + lcd.printString("Mode D",0,0); + lcd.printString("0",2,17); + float pot2_val = pot_2.read(); + RPM = pot2_val*5300+700; + + char RPM_val[27]; + sprintf(RPM_val,"%.0f",RPM); + lcd.printString(RPM_val,25,2); + + lcd.drawRect(5,8,74,7,FILL_TRANSPARENT); // RPM bar + lcd.drawRect(5,30,74,7,FILL_TRANSPARENT); // Speed bar + + float pot2_acc = pot_2.read(); + lcd.drawRect(6,9,pot2_val*74,6,FILL_BLACK); + + lcd.printString("0",3,5); + lcd.printString("137",65,5); + lcd.printString("0",3,2); + lcd.printString("6000",60,2); + + float xr = joy_h.read(); + float yr = joy_v.read(); + + if (button_a.read() == 1) { + + if((xr<0.2)&& (yr<0.2)) { + shift.write(0x31); + gear_ratio=3.62; + } else if((0.8<xr)&& (0.8<yr)) { + shift.write(0x06); + gear_ratio=3.85; + } else if((0.8<xr)&& (yr<0.2)) { + shift.write(0x5B); + gear_ratio=2.04; + } else if((0.4<xr)&& (xr<0.6)&& (0.8<yr)) { + shift.write(0x4F); + gear_ratio=1.28; + } else if((0.4<xr)&&(xr<0.6)&& (yr<0.2)) { + shift.write(0x66); + gear_ratio=0.95; + } else if((xr<0.2)&& (0.8<yr)) { + shift.write(0x6D); + gear_ratio=0.76; + } else { + shift.write(0x3f); + gear_ratio=1000000000; + } + + } + + speed=(0.001174392*RPM*60)/(gear_ratio*4.07); + printf("RPM = %1.0f speed = %.0f mph\n",RPM,speed); + + lcd.drawRect(5,30,speed*37/68,7,FILL_BLACK); + + char speed_val[27]; + sprintf(speed_val,"%.0f",speed); + lcd.printString(speed_val,27,5); + + lcd.refresh(); + wait_ms(100); } - + } \ No newline at end of file
diff -r 76241e21ec61 -r e7e39d27b11f N5110.lib --- a/N5110.lib Mon Mar 13 07:01:51 2017 +0000 +++ b/N5110.lib Thu Jun 29 22:41:30 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/eencae/code/N5110/#d80e568a2e18 +http://mbed.org/users/eencae/code/N5110/#c2598020fcac