Came up with an idea the other day for adding lights to the MPGuino.
Previously posted in the MPGuino release one workspace:
I was thinking about adding code for a 'Red / Green' indicator (2 LEDs hooked up to the outputs) Red would come on if instant was lower than Current, Green would come on if instant was higher than tank. Check to see if backlight was not 0 before turning the light on.
Code:
// in header section
#define GreenLed 10
#define RedLed 11
...
// in setup()
pinMode(GreenLed,OUTPUT);
pinMode(RedLed,OUTPUT);
...
// After sei() call in loop()
if(lastActivity != nil){
if(instantmpg()>tank.mpg()){
//turn on GreenLed
digitalWrite( GreenLed, HIGH);
}else{
//turn off GreenLed
digitalWrite( GreenLed, LOW);
}
if(instantmpg()>current.mpg()){
//turn off RedLed
digitalWrite( RedLed, LOW);
}else{
//turn on RedLed
digitalWrite( RedLed, HIGH);
}
}else{
//turn off both lights if we are in sleep mode.
digitalWrite( RedLed, LOW);
digitalWrite( GreenLed, LOW);
}
Please check the code, I think this is right. Now just install 2 led's on the 10 and 11 pins with drop resistors.
I feel that this would give an instant, eyes up, indication of your driving efficiency based upon bettering your averages. By basing it on both tank and current you will have 4 different states possible:
- Green on, Red off: Better than both Tank and Current avg, you are doing it right.
- Both on or Both off: You are somewhere between current and tank averages, you could be doing better.
- Red on, green off: You are driving too hard or accelerating.