Testing TM1638 + Go-Kart dashboard project

Hello world!

Well… Since my go-kart engine still in maintenance, I found another way to play with TM1638 display that I bought here: http://dx.com/p/8x-digital-tube-8x-key-8x-double-color-led-module-81873

Basically it read the values from the potentiometer and maps to 1 to 10000, more or less the rpm of the engine, and shows at display. Also turns on the leds mapping the value of the potentiometer from 1 to 16.

The small piece of code I wrote to do it is here:

#include <TM1638.h>

TM1638 module(8, 9, 7);
int potpin = 0;
int val;
int val2;
void setup(){}

void loop()
{
val = analogRead(potpin);
val2 = map(val, 0, 1023, 1, 16);
val = map(val, 0, 1023, 0, 10000);

switch (val2) {
case 1:
module.setLEDs(0x1);
break;
case 2:
module.setLEDs(0x3);
break;
case 3:
module.setLEDs(0x7);
break;
case 4:
module.setLEDs(0xF);
break;
case 5:
module.setLEDs(0x1F);
break;
case 6:
module.setLEDs(0x3F);
break;
case 7:
module.setLEDs(0x7F);
break;
case 8:
module.setLEDs(0xFF);
break;
case 9:
module.setLEDs(0x100);
break;
case 10:
module.setLEDs(0x300);
break;
case 11:
module.setLEDs(0x700);
break;
case 12:
module.setLEDs(0xF00);
break;
case 13:
module.setLEDs(0x1F00);
break;
case 14:
module.setLEDs(0x3F00);
break;
case 15:
module.setLEDs(0x7F00);
break;
case 16:
module.setLEDs(0xFF00);
break;
}
module.setDisplayToDecNumber(val,0,false);
delay(1);
}

More detailed information about how to use the TM1638 you can find here:

http://tronixstuff.wordpress.com/2012/03/11/arduino-and-tm1638-led-display-modules/

Also from this link above comes my inspiration to the dashboard I’m planning to do for my go-kart, this video:

More information about this project you can find here:

http://fergotech.net/diy-shift-lights-and-dashboard/

That’s why I bought magnetic switches… The idea is that one of this goes to rear axle, and each time ir switch from 0 to 1, Arduino reads it, calculate the time needed to turn one time and convert to km/h, according to the tire circumference.

Same for the RPM, each turn of the engine is has X milliseconds, based on that it’s possible to calculate how much rotations per minute it represents.

On both cases it’ll be used Arduino’s millis() function. Maybe for RPM I’ll need micros() instead, but I’m not sure yet. According to my calculations, millis() could not be so precise for this case… But I’ll need to test, and for sure I’ll post it here.

Have fun!

Leave a Reply