Update loop to 60fps. Update some arduino devices to 115200. Refactor shiftlights code for performance.
This commit is contained in:
@@ -7,15 +7,15 @@
|
||||
#define NUM_LEDS 6
|
||||
#define BRIGHTNESS 40
|
||||
|
||||
#define COLOR1A 0
|
||||
#define COLOR1R 0
|
||||
#define COLOR1G 255
|
||||
#define COLOR1B 0
|
||||
#define COLOR1C 255
|
||||
#define COLOR2A 0
|
||||
#define COLOR2B 255
|
||||
#define COLOR2C 0
|
||||
#define COLOR3A 255
|
||||
#define COLOR2R 255
|
||||
#define COLOR2G 255
|
||||
#define COLOR2B 0
|
||||
#define COLOR3R 255
|
||||
#define COLOR3G 0
|
||||
#define COLOR3B 0
|
||||
#define COLOR3C 0
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
ShiftLightsData sd;
|
||||
@@ -39,62 +39,69 @@ void setup()
|
||||
}
|
||||
FastLED.clear();
|
||||
|
||||
sd.rpm = 0;
|
||||
sd.maxrpm = 6500;
|
||||
sd.litleds = 0;
|
||||
//sd.rpm = 0;
|
||||
//sd.maxrpm = 6500;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int l = 0;
|
||||
int lit = sd.litleds;
|
||||
char buff[SIMDATA_SIZE];
|
||||
|
||||
if (Serial.available() >= SIMDATA_SIZE)
|
||||
{
|
||||
Serial.readBytes(buff, SIMDATA_SIZE);
|
||||
memcpy(&sd, &buff, SIMDATA_SIZE);
|
||||
rpm = sd.rpm;
|
||||
maxrpm = sd.maxrpm;
|
||||
lit = sd.litleds;
|
||||
}
|
||||
//if (Serial.available() >= SIMDATA_SIZE)
|
||||
//{
|
||||
// Serial.readBytes(buff, SIMDATA_SIZE);
|
||||
// memcpy(&sd, &buff, SIMDATA_SIZE);
|
||||
// rpm = sd.rpm;
|
||||
// maxrpm = sd.maxrpm;
|
||||
//}
|
||||
|
||||
while (l < numlights)
|
||||
{
|
||||
lights[l] = 0;
|
||||
l++;
|
||||
}
|
||||
l = -1;
|
||||
int rpmlights = 0;
|
||||
while (rpm > rpmlights)
|
||||
{
|
||||
if (l>=0)
|
||||
{
|
||||
lights[l] = 1;
|
||||
}
|
||||
l++;
|
||||
rpmlights = rpmlights + (((maxrpm-250)/numlights));
|
||||
}
|
||||
//while (l < numlights)
|
||||
//{
|
||||
// lights[l] = 0;
|
||||
// l++;
|
||||
//}
|
||||
//l = -1;
|
||||
//int rpmlights = 0;
|
||||
//while (rpm > rpmlights)
|
||||
//{
|
||||
// if (l>=0)
|
||||
// {
|
||||
// lights[l] = 1;
|
||||
// }
|
||||
// l++;
|
||||
// rpmlights = rpmlights + (((maxrpm-250)/numlights));
|
||||
//}
|
||||
|
||||
l = 0;
|
||||
FastLED.clear();
|
||||
while (l < numlights)
|
||||
while (l < lit)
|
||||
{
|
||||
|
||||
if (l >= numlights / 2)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR1A, COLOR1B, COLOR1C);
|
||||
leds[l] = CRGB ( COLOR2R, COLOR2G, COLOR2B);
|
||||
}
|
||||
if (l < numlights / 2)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR2A, COLOR2B, COLOR2C);
|
||||
leds[l] = CRGB ( COLOR1R, COLOR1G, COLOR1B);
|
||||
}
|
||||
if (l == numlights - 1)
|
||||
{
|
||||
leds[l] = CRGB ( COLOR3A, COLOR3B, COLOR3C);
|
||||
leds[l] = CRGB ( COLOR3R, COLOR3G, COLOR3B);
|
||||
}
|
||||
if (lights[l] <= 0)
|
||||
{
|
||||
leds[l] = CRGB ( 0, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
//if (lights[l] <= 0)
|
||||
//{
|
||||
// leds[l] = CRGB ( 0, 0, 0);
|
||||
//}
|
||||
l++;
|
||||
}
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user