Pal Kike
porfa regalame un B18unknown
javascript
3 years ago
4.9 kB
4
Indexable
//Daihatsu K3-VE2 shift light v1.4. //Another ridiculously good modification by Mick ;) //Code originally from u/Pyr0monk3y. //Removed all unneeded code for buttons and different modes ect. //Modified pixel code for use with 16 pixel strip. //Individual pixel colour and RPM now adjustable. //Added notes and instructions for easy modification/adjustment by others. //Default operating range 3700 to 7050 rpm (green, yellow, orange, red, blue). //Shift flash @ 7050 to 7500rpm (all blue). //Overrev flash @ >7500 rpm (all red). //Default= 4 cylinder engine. //For use on other engines or for other shift points, rpm frequency needs to be adjusted accordingly. //Mick`s simplified circuit diagram and additional info avaliable @ https://livetodai.com/t/audruino-shift-light/2504/1 //Original code and circuit diagram avaliable @ https://www.reddit.com/r/arduino/comments/515vsd/my_progressive_shift_light_because_racecar/ //initialize libraries #include <Adafruit_NeoPixel.h> #define PIN 6 //LED Data Pin #define NUMPIXELS 16 //number of leds connected Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //Progressive lights from 3700 RPM to 7050 RPM, smooth color transition from green to red, then blue. //shift @7050 until 7500, all flashing blue. //overrev @>7500, all flashing red. //to change rpm values change igfreq (frquency values are different depending on no. of cylinders). //RPM to Frequency chart avaliable @ https://adaptronicecu.com/blogs/modular-instructional-videos/how-to-setup-tacho-on-modular-ecus //4 cylinder engine, sequential ignition Hz=RPM/30. //4 Cylinder engine, wasted spark Hz=(RPM/30)x2. //Set operating range (default=123hz to 235hz = 3700rpm to 7050rpm @ 4 cylinder sequential) const unsigned int minFrequency = 123; // minimum frequency to begin turning on LEDs const unsigned int maxFrequency = 235; // maximum frequency in normal range const unsigned int shiftFrequency = 250; // frequency range from max to shift when shifting should happen // colors for each pixel when on const uint32_t tachColor[NUMPIXELS] = { Adafruit_NeoPixel::Color(0, 120, 0), Adafruit_NeoPixel::Color(0, 120, 0), Adafruit_NeoPixel::Color(0, 120, 0), Adafruit_NeoPixel::Color(15, 105, 0), Adafruit_NeoPixel::Color(30, 90, 0), Adafruit_NeoPixel::Color(45, 75, 0), Adafruit_NeoPixel::Color(60, 60, 0), Adafruit_NeoPixel::Color(75, 45, 0), Adafruit_NeoPixel::Color(90, 30, 0), Adafruit_NeoPixel::Color(105, 15, 0), Adafruit_NeoPixel::Color(120, 0, 0), Adafruit_NeoPixel::Color(0, 0, 120), Adafruit_NeoPixel::Color(0, 0, 120), Adafruit_NeoPixel::Color(0, 0, 120), Adafruit_NeoPixel::Color(0, 0, 120), Adafruit_NeoPixel::Color(0, 0, 120), }; /* list of frequencies to determine when LEDs get turned on. for a given index if the frequency is above this value, the LED will be on using the colors above otherwise, it will be off. These steps do not need to be linear but must start with minFrequency and not exceed maxFrequency */ const unsigned int lightShiftFreq[NUMPIXELS] = { minFrequency, 130, 137, 144, 151, 158, 165, 172, 179, 186, 193, 200, 207, 214, 221, 228, }; int i; const byte tachPin = 2; void setup() { pixels.begin(); // This initializes the NeoPixel library. } unsigned long igfreq; void loop() { // int rpm; float ighigh, iglow; unsigned long igcal1, igcal2; //measure period of tach signal ighigh = pulseIn(tachPin, HIGH); iglow = pulseIn(tachPin, LOW); igcal1 = 1000 / ((ighigh / 1000) + (iglow / 1000)); //do it again ighigh = pulseIn(tachPin, HIGH); iglow = pulseIn(tachPin, LOW); igcal2 = 1000 / ((ighigh / 1000) + (iglow / 1000)); //to filter out some noise, we only consider our measurement valid if they are similar in value, we accept the average. if ((igcal1 - igcal2) < 8) { igfreq = (igcal1 + igcal2) / 2; } if (igfreq >= minFrequency && igfreq < maxFrequency) { // normal operating range for ( int i = 0; i < NUMPIXELS; ++i) { if (igfreq > lightShiftFreq[i]) { pixels.setPixelColor(i, tachColor[i]); } else { pixels.setPixelColor(i, pixels.Color(0, 0, 0)); } } pixels.show(); } else if (igfreq >= maxFrequency && igfreq < shiftFrequency) { //shift flash //default color=blue pixels.fill(pixels.Color(0, 0, 120)); pixels.show(); delay(20); pixels.fill(pixels.Color(0, 0, 0)); pixels.show(); delay(20); } else if (igfreq >= shiftFrequency) { //overrev flash //default color=red pixels.fill(pixels.Color(120, 0, 0)); pixels.show(); delay(20); pixels.fill(pixels.Color(0, 0, 0)); pixels.show(); delay(20); } }
Editor is loading...