Hello all. I have a sketch that reads a cars ECU via OBD that all works great but now its time to move on and actually displaying some info. Am looking at using the i2c bus to control LEDs and seven segments but to start with i just want to use 8 LEDs to show RPM (1 LED = 1000RPM).
#define ERPM 0x0C //Engine RPM.
//Main.
void loop()
{
unsigned long result = 0;
get_PID(ERPM, &result);
if(result <= 999)
{
// B00000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 1000 && result <= 1999)
{
//B10000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 2000 && result <= 2999)
{
//B11000000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 3000 && result <= 3999)
{
//B11100000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 4000 && result <= 4999)
{
//B11110000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 5000 && result <= 5999)
{
//B11111000 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 6000 && result <= 6999)
{
//B11111100 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 7000 && result <= 7999)
{
//B11111110 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
else if(result >= 8000 && result <= 8999)
{
//B11111111 value to be displayed on 8 LEDs. 1 = LED on, 0 = LED off.
}
}
A little info about the above, unsigned long result = 0; is a variable that will contain anything from 0 to 9000 and get_PID(ERPM, &result); is the command that gets the info from the car that works fine.
As you can see from the above that i want to turn on some LEDs over i2c (to the LED driver) to show the rpm. Am i better using some kind of for loop and place the binary valuse in a const struct or array or PROGMEN?
Any ideas or examples would be great. In the end i will be adding more i2c ic's to display speed on a seven segment.