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 mbed-rtos WattBob_TextLCD
Diff: main.cpp
- Revision:
- 10:5f6d15f8fc79
- Parent:
- 9:c3c90e137cfb
- Child:
- 11:7a8cfd29b124
--- a/main.cpp Wed Mar 28 10:04:58 2018 +0000
+++ b/main.cpp Wed Mar 28 13:36:53 2018 +0000
@@ -10,19 +10,16 @@
MCP23017 *par_port; // pointer to 16-bit parallel I/O object
WattBob_TextLCD *lcd; // pointer to 2*16 chacater LCD object
-AnalogIn accel(p15); // Analog
+AnalogIn accel(p15); // Analog in
AnalogIn brake(p16);
-float speed;
+
+float speed; // IO values
float kmph;
float aveSpeed;
float acc;
float br;
float distance = 0;
-Timer tim, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;// integrate with wait?
-
-int indicount = 0;
-
DigitalOut sideLights(LED1); // mbed out
DigitalOut lIndicator(LED2);
DigitalOut rIndicator(LED3);
@@ -31,34 +28,29 @@
DigitalOut brakeLights(p6); // redbox out
DigitalOut fluxCapacitor(p7);
-DigitalIn engine(p5); // switches
+DigitalIn engine(p5); // switches in
DigitalIn lightSwitch(p8);
DigitalIn lIndicate(p11);
DigitalIn rIndicate(p12);
-int l, r, lr;
+int l, r, lr; // indicator values
Serial pc(USBTX, USBRX); // serial tx, rx
-Thread sp;
+Thread sp; // threads. Speed
Thread task1;
Thread task246;
Thread task3;
-//Thread task4;
Thread task59;
-//Thread task6;
Thread task7;
Thread task8;
-//Thread task9;
Thread task10;
-Thread indi;
-Semaphore ac(1);
+Thread indi; // indicators
-typedef struct { // mail
+typedef struct { // mail
float m_speed;
float m_acc;
float m_br;
- uint32_t counter; // A counter value
} mail_t;
Mail<mail_t, 100> mail_box;
@@ -92,6 +84,8 @@
} else {
engLight = 0;
aveSpeed = 0;
+ acc = 0;
+ br = 0;
}
}
void speedo() // 3. Average last n speed readings thread 5
@@ -132,7 +126,7 @@
{
while (true) {
mail_t *mail = mail_box.alloc();
- mail->m_speed = kmph;
+ mail->m_speed = aveSpeed;
mail->m_acc = acc;
mail->m_br = br;
mail_box.put(mail);
@@ -140,7 +134,7 @@
Thread::wait(5000);
}
}
-void toSerial() // 8. MAIL q to serial PC thread 0.05
+void toSerial() // 8. MAILq to serial PC thread 0.05
{
while (1) {
osEvent evt = mail_box.get();
@@ -154,8 +148,8 @@
}
void lights() // 9. set side lights subroutine 1
{
- if (lightSwitch.read() == 1) {
- sideLights = 1;
+ if (lightSwitch.read() == 1) { // If light switch on
+ sideLights = 1; // turn on side lights
} else {
sideLights = 0;
}