This code work perfectly on the UNO, but cannot seem to get it to work on Leonardo.
Totally puzzled....
#define REVERSE
#ifdef REVERSE
#include <InvertedTM1638.h>
#else
#include <TM1638.h>
#endif
const int DATA_PIN=8;
const int CLOCK_PIN=9;
const int STROBE_PIN=7;
#ifdef REVERSE
InvertedTM1638 module(DATA_PIN, CLOCK_PIN, STROBE_PIN);
#else
TM1638 module(DATA_PIN, CLOCK_PIN, STROBE_PIN);
#endif
byte Gear;
int Speed, Fuel_Remaining;
String Velocidad, Velocidad2;
String Fuel, Fuel2;
word Vel;
byte TramaSerie[8];
short int Puntero,Modo_Hud;
//57375
word leds [10] = {0, 1, 3, 7, 15, 31, 8223, 24607, 57375, 65535};
void setup()
{
// Inicializar puerto serie a 9600 baudios
Serial.begin(9600);
Modo_Hud=-1;
}
void loop()
{
if (Serial.available()>0)
{
if (Serial.available()>8)
{
Puntero=0;
memset(TramaSerie, 0, sizeof(TramaSerie));
TramaSerie[Puntero]=Serial.read();
if (TramaSerie[Puntero]==0xFF)
{
for (Puntero=1; Puntero<8; Puntero++)
{
TramaSerie[Puntero]=Serial.read();
}
if( TramaSerie[1]!=Modo_Hud)
{
module.clearDisplay();
}
switch(TramaSerie[1])
{
case 0: Display_Velocidad();
break;
case 1: Display_Fuel();
break;
default: Display_Velocidad();
break;
}
module.setLEDs(leds[TramaSerie[5]]);
Modo_Hud=TramaSerie[1];
}
}
}
}
void Display_Velocidad()
{
switch(TramaSerie[2])
{
case 255:
module.setDisplayToString("r", 0,0);
break;
case 0:
module.setDisplayToString("N", 0,0);
break;
default:
module.setDisplayToString(String(TramaSerie[2],DEC), 0,0);
}
Vel=(TramaSerie[4] << 8)| TramaSerie[3];
Velocidad=String(Vel,DEC);
Speed=Velocidad.length();
switch (Speed)
{
case 1: Velocidad2=" "+Velocidad;
break;
case 2: Velocidad2=" "+Velocidad;
break;
default: Velocidad2=Velocidad;
break;
}
module.setDisplayToString(Velocidad2, 0,5);
}
void Display_Fuel()
{
module.setDisplayToString("FUEL",0,0);
Fuel=String(TramaSerie[6], DEC);
Fuel_Remaining=Fuel.length();
switch (Fuel_Remaining)
{
case 1: Fuel2=" "+Fuel;
break;
case 2: Fuel2=" "+Fuel;
break;
default: Fuel2=Fuel;
break;
}
module.setDisplayToString(Fuel2, 0, 5);
}
It seems to not serial the information.