automotive simulation thingy
Dependencies: N5110 ShiftReg Tone mbed
Fork of 1620_Project_Template by
ModeC/ModeC.cpp@2:e7e39d27b11f, 2017-06-29 (annotated)
- Committer:
- Al_Husien_Dabashi
- Date:
- Thu Jun 29 22:41:30 2017 +0000
- Revision:
- 2:e7e39d27b11f
- Parent:
- 0:d5312060f649
1620 Final Automotive simulation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:d5312060f649 | 1 | #include "ModeC.h" |
eencae | 0:d5312060f649 | 2 | |
eencae | 0:d5312060f649 | 3 | void mode_C() |
eencae | 0:d5312060f649 | 4 | { |
eencae | 0:d5312060f649 | 5 | |
eencae | 0:d5312060f649 | 6 | lcd.clear(); |
eencae | 0:d5312060f649 | 7 | lcd.printString("Mode C",0,0); |
eencae | 0:d5312060f649 | 8 | lcd.refresh(); |
eencae | 0:d5312060f649 | 9 | wait_ms(250); // small delay to prevent previous press being detected again |
eencae | 0:d5312060f649 | 10 | |
eencae | 0:d5312060f649 | 11 | while (button_c.read() == 0) { |
eencae | 0:d5312060f649 | 12 | // code goes in here - this acts like the main while(1) loop |
eencae | 0:d5312060f649 | 13 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 14 | lcd.clear(); |
eencae | 0:d5312060f649 | 15 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 16 | lcd.printString("Mode C",0,0); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 17 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 18 | float pot0_val1 = pot_0.read(); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 19 | float dist_cm = pot0_val1*200; |
Al_Husien_Dabashi | 2:e7e39d27b11f | 20 | printf("Gap distance = %.0f cm\n",dist_cm); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 21 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 22 | speaker.init(); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 23 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 24 | float t = dist_cm*19/4000+0.05; |
Al_Husien_Dabashi | 2:e7e39d27b11f | 25 | speaker.play(1000,t); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 26 | // printf("%0.2f\n",t); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 27 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 28 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 29 | float W1=pot0_val1*-75+75; |
Al_Husien_Dabashi | 2:e7e39d27b11f | 30 | lcd.drawRect(3,27,75,12,FILL_TRANSPARENT); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 31 | lcd.drawRect(3,27,W1,12,FILL_BLACK); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 32 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 33 | if (dist_cm<20) { |
Al_Husien_Dabashi | 2:e7e39d27b11f | 34 | blue_led.write(1); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 35 | red_led.write(0); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 36 | green_led.write(1); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 37 | } else { |
Al_Husien_Dabashi | 2:e7e39d27b11f | 38 | blue_led.write(1); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 39 | red_led.write(1); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 40 | green_led.write(1); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 41 | } |
Al_Husien_Dabashi | 2:e7e39d27b11f | 42 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 43 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 44 | int arrow[5][20] = { |
Al_Husien_Dabashi | 2:e7e39d27b11f | 45 | { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 }, |
Al_Husien_Dabashi | 2:e7e39d27b11f | 46 | { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 }, |
Al_Husien_Dabashi | 2:e7e39d27b11f | 47 | { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, |
Al_Husien_Dabashi | 2:e7e39d27b11f | 48 | { 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 }, |
Al_Husien_Dabashi | 2:e7e39d27b11f | 49 | { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 }, |
Al_Husien_Dabashi | 2:e7e39d27b11f | 50 | }; |
Al_Husien_Dabashi | 2:e7e39d27b11f | 51 | lcd.drawSprite(30,20,5,20,(int *)arrow); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 52 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 53 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 54 | |
Al_Husien_Dabashi | 2:e7e39d27b11f | 55 | lcd.refresh(); |
Al_Husien_Dabashi | 2:e7e39d27b11f | 56 | wait(t); |
eencae | 0:d5312060f649 | 57 | } |
eencae | 0:d5312060f649 | 58 | |
eencae | 0:d5312060f649 | 59 | } |