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: MCP23017 Servo WattBob_TextLCD mbed mbed-rtos
Revision 9:8ac963c7e3a1, committed 2017-04-05
- Comitter:
- xouf2114
- Date:
- Wed Apr 05 13:08:32 2017 +0000
- Parent:
- 8:9e8a5014cc0f
- Commit message:
- Commit
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Apr 05 12:06:42 2017 +0000
+++ b/main.cpp Wed Apr 05 13:08:32 2017 +0000
@@ -22,14 +22,14 @@
MCP23017 *par_port; // pointer to 16-bit parallel I/O object
WattBob_TextLCD *lcd; // pointer to 2*16 chacater LCD object
-Serial serpc(USBTX, USBRX); // serial usb connection tx, rx
+Serial serpc(USBTX, USBRX); // serial usb connection tx, rx
AnalogIn AinBreak(p18); // Port for the Break Value
AnalogIn AinAccel(p19); // Port for the Accelerator Value
DigitalIn DinSwitchEngine(p11); // Port for the Engine Switch
DigitalIn DinSwitchLight(p12); // Port for the Light Switch
DigitalIn DinSwitchRindic(p13); // Port for the Right Indicator
DigitalIn DinSwitchLindic(p15); // Port for the Left Indicator
-Servo Odometer(p25);
+Servo Odometer(p21);
DigitalOut LEDSpeedWarning(p8);
DigitalOut DoutLEDLight(LED1); // Output Port for LED1
DigitalOut DoutLEDLeft(LED2); // Output Port for LED2
@@ -40,6 +40,7 @@
void Timer3_void(void const *args); // Timer 3
+
// Task Functions
void Task_1_break_accelerate();
void Task_2_read_show_engine_state();
@@ -240,6 +241,7 @@
// Let the Semaphores release
SemAvgSpeed.release();
}
+
/*
Indicates a Speed warning at 75 Mph
*/
@@ -311,6 +313,7 @@
// Release the Semaphores
SemMailCnT.release();
}
+
/*
Single Side Light
*/
@@ -318,6 +321,7 @@
{
DoutLEDLight = DinSwitchLight; // Reading the value
}
+
/*
Reads the Left and Right Inidcator
*/
@@ -326,6 +330,7 @@
indicator_R = DinSwitchRindic; // Reading the value
indicator_L = DinSwitchLindic; // Reading the value
}
+
/*
Calculates the Average Speed
*/
@@ -342,6 +347,7 @@
SemAvgSpeedDB.release();
SemAvgSpeed.release();
}
+
/*
Emulates the car
*/
@@ -354,13 +360,13 @@
SemBreak_Accelerate.wait();
SemSpeed.wait();
SemEngine.wait();
-if(accerlator<=brake || !engine) // are we braking more than accelerating? is the engine on?
+if(accerlator<=brake || !engine) // are we braking more than accelerating? is the engine on?
speed = 0;
else
speed = (accerlator-brake) *0.5 +speed;
if(speed>250)
speed=250; // maximum speed
-if(AvgSpeedDB.size()>=4) // if we already got 4 values, we have to
+if(AvgSpeedDB.size()>=4) // if we already got 4 values, we have to
AvgSpeedDB.pop_front(); // make space by deleting the oldest value
AvgSpeedDB.push_back(speed); // safe a new reading
dist += speed * 1.0/20.0; // runs at 20 Hz so we have to take this into account
@@ -372,10 +378,11 @@
SemSpeed.release();
SemEngine.release();
}
+
/*
Function used for converting Hz to Ms for a Steps
*/
-int Convert_Hz_to_Ms(double Hz)
+int Convert_Hz_to_Ms(double Hz) // Convert Hz into ms
{
return 1000.0 / Hz;
}