Files
monocoque/src/arduino/shiftlights/shiftlights.ino
T

85 lines
1.7 KiB
Arduino
Raw Normal View History

2022-10-31 15:11:02 +00:00
#include <FastLED.h>
2024-03-05 00:34:29 -05:00
#include "shiftlights.h"
2022-10-31 15:11:02 +00:00
#define SIMDATA_SIZE sizeof(ShiftLightsData)
2022-10-31 15:11:02 +00:00
#define LED_PIN 7
#define NUM_LEDS 6
#define BRIGHTNESS 40
2025-01-02 16:21:15 -05:00
#define STARTLED 1
2022-10-31 15:11:02 +00:00
#define COLOR1R 0
#define COLOR1G 255
2024-02-17 18:50:57 +00:00
#define COLOR1B 0
#define COLOR2R 255
#define COLOR2G 255
#define COLOR2B 0
#define COLOR3R 255
#define COLOR3G 0
2024-02-17 18:50:57 +00:00
#define COLOR3B 0
2022-10-31 15:11:02 +00:00
CRGB leds[NUM_LEDS];
2024-03-05 00:34:29 -05:00
ShiftLightsData sd;
2022-10-31 15:11:02 +00:00
int maxrpm = 0;
int rpm = 0;
int numlights = NUM_LEDS;
int pin = LED_PIN;
2025-01-02 15:54:46 -05:00
int lights[NUM_LEDS];
2022-10-31 15:11:02 +00:00
void setup()
{
2025-01-02 15:54:46 -05:00
Serial.begin(115200);
2022-10-31 15:11:02 +00:00
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.setBrightness(BRIGHTNESS);
for (int i = 0; i < numlights; i++)
{
leds[i] = CRGB ( 0, 0, 0);
lights[i] = 0;
}
FastLED.clear();
sd.litleds = 0;
//sd.rpm = 0;
//sd.maxrpm = 6500;
2022-10-31 15:11:02 +00:00
}
void loop()
{
int l = 0;
int lit = sd.litleds;
char buff[SIMDATA_SIZE];
2022-10-31 15:11:02 +00:00
if (Serial.available() >= SIMDATA_SIZE)
2022-10-31 15:11:02 +00:00
{
Serial.readBytes(buff, SIMDATA_SIZE);
memcpy(&sd, &buff, SIMDATA_SIZE);
lit = sd.litleds;
2022-10-31 15:11:02 +00:00
}
l = 0;
FastLED.clear();
while (l < lit)
2022-10-31 15:11:02 +00:00
{
if (l >= numlights / 2)
{
2025-01-02 16:21:15 -05:00
leds[l+STARTLED-1] = CRGB ( COLOR2R, COLOR2G, COLOR2B);
2022-10-31 15:11:02 +00:00
}
if (l < numlights / 2)
{
2025-01-02 16:21:15 -05:00
leds[l+STARTLED-1] = CRGB ( COLOR1R, COLOR1G, COLOR1B);
2022-10-31 15:11:02 +00:00
}
if (l == numlights - 1)
{
2025-01-02 16:21:15 -05:00
leds[l+STARTLED-1] = CRGB ( COLOR3R, COLOR3G, COLOR3B);
2022-10-31 15:11:02 +00:00
}
//if (lights[l] <= 0)
//{
// leds[l] = CRGB ( 0, 0, 0);
//}
2022-10-31 15:11:02 +00:00
l++;
}
FastLED.show();
2022-10-31 15:11:02 +00:00
}