Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MCP23017 WattBob_TextLCD mbed-rtos
my_tools.cpp
00001 #include "my_tools.h" 00002 00003 using namespace std; 00004 00005 // TASK 1 00006 // Read an analog input and return a float between 0 and 1 00007 float readAnalogInput(AnalogIn pin) 00008 { 00009 return (pin.read()); 00010 } 00011 00012 // Delete first value of the given vector (the head) 00013 void deleteFirstValueVec(vector<float> &vec) 00014 { 00015 vec.erase(vec.begin()); 00016 } 00017 00018 // TASK 4 & 5 00019 int monitorValue(float value, DigitalOut led, float thresholdValue) 00020 { 00021 if (value > thresholdValue) 00022 { 00023 led = 1; 00024 return (1); 00025 } 00026 else 00027 { 00028 led = 0; 00029 return (0); 00030 } 00031 } 00032 00033 // TASK 6 00034 void writeOnLCD(WattBob_TextLCD &lcd, float odometer, float avg) 00035 { 00036 static bool firstTime = true; 00037 /* We clear the LCD only the first time this function is run */ 00038 if (firstTime) 00039 { 00040 /* Clear Display */ 00041 lcd.cls(); 00042 00043 /* Print Distance */ 00044 lcd.locate(0, 0); 00045 lcd.printf("D km: "); 00046 00047 /* Print Avg Values of Speed */ 00048 lcd.locate(1, 0); 00049 lcd.printf("S kmh: "); 00050 00051 firstTime = false; 00052 } 00053 00054 /* Print Distance */ 00055 lcd.locate(0, 7); 00056 lcd.printf("%.2f", odometer/1000); 00057 00058 /* Print Avg Value of Speed */ 00059 lcd.locate(1, 7); 00060 lcd.printf("%05.1f", avg*3.6); 00061 } 00062 00063 // TASK 10 00064 void updateLEDs(carStructure *myCar, bool right, bool left) 00065 { 00066 if (right && left) 00067 { 00068 // Both ON - 2Hz 00069 myCar->p_rightLight->period_ms(500); 00070 myCar->p_rightLight->pulsewidth_ms(250); 00071 00072 myCar->p_leftLight->period_ms(500); 00073 myCar->p_leftLight->pulsewidth_ms(250); 00074 } 00075 else if (right) 00076 { 00077 // Only right - 1Hz 00078 myCar->p_rightLight->period_ms(1000); 00079 myCar->p_rightLight->pulsewidth_ms(500); 00080 00081 myCar->p_leftLight->period_ms(1000); 00082 myCar->p_leftLight->pulsewidth_ms(0); 00083 } 00084 else if (left) 00085 { 00086 // Only left - 1Hz 00087 myCar->p_rightLight->period_ms(1000); 00088 myCar->p_rightLight->pulsewidth_ms(0); 00089 00090 myCar->p_leftLight->period_ms(1000); 00091 myCar->p_leftLight->pulsewidth_ms(500); 00092 } 00093 else 00094 { 00095 // Both OFF 00096 myCar->p_rightLight->period_ms(1000); 00097 myCar->p_rightLight->pulsewidth_ms(0.0); 00098 00099 myCar->p_leftLight->period_ms(1000); 00100 myCar->p_leftLight->pulsewidth_ms(0.0); 00101 } 00102 }
Generated on Wed Jul 13 2022 17:41:33 by
1.7.2