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:
- 6:a026e0651ad5
- Parent:
- 5:e62e0e3084fc
- Child:
- 7:84c2156e1ace
--- a/main.cpp Tue Mar 27 12:56:10 2018 +0000
+++ b/main.cpp Tue Mar 27 13:21:36 2018 +0000
@@ -73,12 +73,12 @@
void getSpeed() // 20Hz calculation for speed & distance
{
while (1) {
- speed = (acc - br)*16.835;
+ speed = (acc - br)*16.835; // speed in m/s. Max = 55
if (speed < 0) {
speed = 0;
}
- kmph = speed*3.6;
- distance = distance + (speed*0.05)/1000;
+ kmph = speed*3.6; // convert speed to km/ph. Change to *2.24 for ~mph
+ distance = distance + (speed*0.05)/1000; // distance = speed*time (/1000 for m to km)
Thread::wait(50);
}
}
@@ -98,9 +98,9 @@
{
while (1) {
for (int i = 0; i<3; i++) {
- aveSpeed = speed + aveSpeed;
+ aveSpeed = kmph + aveSpeed; // in km/h
}
- aveSpeed = speed/4;
+ aveSpeed = aveSpeed/4;
Thread::wait(200);
}
@@ -121,9 +121,12 @@
void greatScott() // 5. if speed > 88 LED on 1
{
while (1) {
- if (speed > 140) {
+ if (kmph > 141.6) { // 141.6 km = 88 miles
fluxCapacitor = 1;
}
+ else{
+ fluxCapacitor = 0;
+ }
Thread::wait(1000);
}
@@ -135,11 +138,11 @@
lcd->locate(0,0);
lcd->printf("KM:%0.1f",distance);
lcd->locate(1,0);
- lcd->printf("KMPH:%.1f",kmph);
+ lcd->printf("KM/H:%.1f",aveSpeed);
lcd->locate(0,8);
//ac.wait();
- //lcd->printf("a:%0.1f",dif);
- lcd->locate(1,8);
+ lcd->printf("sp:%0.1f",kmph);
+ //lcd->locate(1,8);
//ac.release();
//lcd->printf("b:%d",engine.read());
@@ -223,13 +226,13 @@
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); //20
- task1.start(acceleration); //10
-// task2.start(ignition); //2 .setPriority();
-// task3.start(speedo); //5
-// task4.start(braking); //2
-// task5.start(greatScott); //1
- task6.start(LCD); //2
+ sp.start(getSpeed); //20 y
+ task1.start(acceleration); //10 y
+ task2.start(ignition); //2 .setPriority(); y
+ task3.start(speedo); //5 y
+ task4.start(braking); //2 y
+ task5.start(greatScott); //1 y
+ task6.start(LCD); //2 y
// task7.start(callback(send_thread)); //0.2
// task8.start(toSerial); //0.05
// task9.start(lights); //1