Código:
#include
#include
#include
#include
#include
#include
#define OLED_RESET 4
#define PIN 6
#define NUMPIXELS 16
#define BLINKSPD 100
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_SSD1306 display(OLED_RESET);
SoftwareSerial BT1(10,11); // RX, TX
long emillis =0;
int blink_color=pixels.Color(0,0,0);
uint32_t color_green=pixels.Color(0,10,0);
uint32_t color_orange=pixels.Color(10,5,0);
uint32_t color_red=pixels.Color(10,0,0);
uint32_t color_blue=pixels.Color(0,0,30);
long await=0;
uint32_t colors[] ={
color_green,
color_green,
color_green,
color_green,
color_green,
color_green,
color_green,
color_green,
color_orange,
color_orange,
color_orange,
color_orange,
color_red,
color_red,
color_red,
color_blue
};
int currentPosition=0;
int isBlinking=0;
void setup() {
pixels.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
BT1.begin(9600);
drawGear("X");
knightRider(3, 32, 4, pixels.Color(20,2,0)); // Cycles, Speed, Width, RGB Color (original orange-red)
clearStrip();
drawGear("");
}
void loop() {
while (BT1.available()>0) {
int v =BT1.read();
if (v<=15) {
currentPosition = v;
drawRPM();
} else if (v<=17) {
isBlinking=v-16;
drawBlink();
} else if (v<=29) {
switch (v) {
case 18:
drawGear("R");
break;
case 19:
drawGear("N");
break;
default:
drawGear(String(v-19));
}
}
await=millis();
}
if (millis()-await>5000) {
drawGear("");
clearStrip();
await=millis();
}
}
void drawRPM() {
for(int i=0;i0) {
if (millis()-emillis>=BLINKSPD){
if (blink_color==pixels.Color(0,0,0)) {
blink_color=colors[NUMPIXELS-1];
} else {
blink_color=pixels.Color(0,0,0);
}
emillis=millis();
}
} else {
blink_color=pixels.Color(0,0,0);
}
pixels.setPixelColor(NUMPIXELS-1, blink_color);
pixels.show();
}
void drawGear (String g) {
display.clearDisplay();
if (isBlinking>0) {
if (millis()-emillis>=BLINKSPD){
if (blink_color==pixels.Color(0,0,0)) {
display.invertDisplay(true);
} else {
display.invertDisplay(false);
}
}
} else {
display.invertDisplay(false);
}
display.setTextSize(9);
display.setTextColor(WHITE);
display.setCursor(43,0);
display.println(g);
display.display();
}
void knightRider(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) {
uint32_t old_val[NUMPIXELS];
for(int i = 0; i < cycles; i++){
for (int count = 1; count0; x--) {
old_val[x-1] = dimColor(old_val[x-1], width);
pixels.setPixelColor(x-1, old_val[x-1]);
}
pixels.show();
delay(speed);
}
for (int count = NUMPIXELS-1; count>=0; count--) {
pixels.setPixelColor(count, color);
old_val[count] = color;
for(int x = count; x<=NUMPIXELS ;x++) {
old_val[x-1] = dimColor(old_val[x-1], width);
pixels.setPixelColor(x+1, old_val[x+1]);
}
pixels.show();
delay(speed);
}
}
}
void clearStrip() {
isBlinking=0;
for( int i = 0; i
El código podría ser mucho mas pequeño, pero le he puesto una pequeña animación al arrancar para darle un toque de gracia.
Código:
Imports iRSDKSharp
Private Sub ProcessData()
Dim Gear As Integer
Dim Rpm, RpmP As Double
Dim LedCount As Byte = 0
Integer.TryParse(_Sdk.GetData("Gear"), Gear)
Rpm = _Sdk.GetData("RPM")
Counter += 1
If Counter = 100 Then
If Rpm = 0 Then
Restart()
Exit Sub
End If
Counter = 0
End If
If _SessionInfo <> _Sdk.GetSessionInfo Then
_SessionInfo = _Sdk.GetSessionInfo()
_MaxRpm = Double.Parse(YamlParser.Parse(_SessionInfo, "DriverInfo:DriverCarSLShiftRPM:"), NumberStyles.Any, CultureInfo.InvariantCulture)
End If
RpmP = Rpm * 100.0 / _MaxRpm
Select Case RpmP
Case Is > 99
LedCount = 15
Case Is > 97.6
LedCount = 14
Case Is > 96.0
LedCount = 13
Case Is > 94
LedCount = 12
Case Is > 91.6
LedCount = 11
Case Is > 87.5
LedCount = 10
Case Is > 82.5
LedCount = 9
Case Is > 76.6
LedCount = 8
Case Is > 70
LedCount = 7
Case Is > 62.5
LedCount = 6
Case Is > 54.1
LedCount = 5
Case Is > 45
LedCount = 4
Case Is > 35
LedCount = 3
Case Is > 24.1
LedCount = 2
Case Is > 12.5
LedCount = 1
Case Else
LedCount = 0
End Select
SerialSend(LedCount, Gear)
End Sub
Private Sub SerialSend(LedCount As Integer, Gear As Integer)
Dim data(2) As Byte
data(0) = LedCount
Data(1) = 16 + IIf(LedCount = 15, 1, 0)
Data(2) = Gear + 19
_Serial.Write(data, 0, 3)
End Sub
Y poco más. Si alguno os quereis hacer uno igual o parecido preguntad y intentaré resolver vustras dudas. Soys libres de usar el código, la idea o los diseños 3d para lo que queráis aunque si lo haceis os agradeceré que me mencioneis ;)
Marcadores