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:
- 2:51a06b9a52d1
- Parent:
- 1:c2c4bd530112
- Child:
- 3:d888509e77b8
--- a/main.cpp Wed Mar 21 12:50:48 2018 +0000
+++ b/main.cpp Mon Mar 26 14:47:56 2018 +0000
@@ -22,19 +22,21 @@
Timer tim;
long int t;
-DigitalOut sideLights(LED1);
+DigitalOut sideLights(LED1);// mbed out
DigitalOut lIndicator(LED2);
DigitalOut rIndicator(LED3);
DigitalOut engLight(LED4);
-DigitalOut brakeLights(p6);
+DigitalOut brakeLights(p6);// redbox out
DigitalOut fluxCapacitor(p7);
-DigitalIn lightSwitch(p8);
+DigitalIn lightSwitch(p8);// switches
DigitalIn lIndicate(p9);
DigitalIn rIndicate(p10);
DigitalIn engine(p5);
+Serial pc(USBTX, USBRX);// serial tx, rx
+
Thread sp;
Thread task1;
Thread task2;
@@ -47,6 +49,41 @@
Thread task9;
Thread task10;
+/* Mail */
+typedef struct {
+ float m_speed;
+ float m_acc;
+ float m_br;
+ uint32_t counter; /* A counter value */
+} mail_t;
+
+Mail<mail_t, 100> mail_box;
+
+void send_thread (void)
+{
+ uint32_t i = 0;
+ while (true) {
+ i++; // fake data update
+ mail_t *mail = mail_box.alloc();
+ mail->m_speed = speed;
+ mail->m_acc = acc;
+ mail->m_br = br;
+ mail->counter = i;
+ mail_box.put(mail);
+
+ osEvent evt = mail_box.get();
+ if (evt.status == osEventMail) {
+ mail_t *mail = (mail_t*)evt.value.p;
+ printf("\nSpeed: %.2f \n\r" , mail->m_speed);
+ printf("Acceleration: %.2f \n\r" , mail->m_acc);
+ printf("Braking: %.2f \n\r", mail->m_br);
+
+ mail_box.free(mail);
+ }
+ Thread::wait(5000);
+ }
+}
+
void acceleration() //run at 20hz // 1 read brake and accelerator 10
{
@@ -134,9 +171,8 @@
while (1) {
if (lightSwitch == 1) {
sideLights = 1;
- }
- else{
- sideLights = 0;
+ } else {
+ sideLights = 0;
}
Thread::wait(1000);
@@ -162,6 +198,18 @@
Thread::wait(2000);
}
}
+void toSerial()//7
+{
+ while (1) {
+ osEvent evt = mail_box.get();
+ mail_t *mail = (mail_t*)evt.value.p;
+ pc.printf("\nSpeed: %.2f \n\r", mail->m_speed);
+ pc.printf("Acceleration: %.2f \n\r", mail->m_acc);
+ pc.printf("Braking: %.2f \n\r", mail->m_br);
+
+ Thread::wait(20000);
+ }
+}
int main()
{
@@ -169,18 +217,17 @@
lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display
par_port->write_bit(1,BL_BIT); // turn LCD backlight ON
- sp.start(getSpeed);
- task1.start(acceleration);
- task2.start(ignition);
- task3.start(speedo);
- task4.start(braking);
- task5.start(greatScott);
- task6.start(LCD);
- //task7.start();
- //task8.start();
- task9.start(lights);
- task10.start(indicators);
-
+ sp.start(getSpeed); //20
+ task1.start(acceleration); //10
+ task2.start(ignition); //2
+ task3.start(speedo); //5
+ task4.start(braking); //2
+ task5.start(greatScott); //1
+ task6.start(LCD); //2
+ task7.start(callback(send_thread)); //0.2
+ //task8.start(); //0.05
+ task9.start(lights); //1
+ task10.start(indicators); //0.5
}