I'm starting to play with a WS2812B led strip and I'd like to make an animation... Years ago I made a shift light with very simple animations but I'd like to do something more worked.
I show an example of what I want to do...
In the video, you can see how while the rpm's increase, the brightness also varies from each led.
I'm doing tests to get that effect and the only way I get it is with this code.
Your code is slow because you are adding brightness to each LED from 0 to 255 as you move from LED to LED. If you unwrap that for() loop and set b=255 it will be very fast. (too fast to see).
Create an array of "RPM" data (or connect a potentiometer to an Analog Input pin).
Read each array element (or read the potentiometer).
Map the data (array or potentiometer) and pass it to the logic loop.
I already knew about the simhub app and installed it before asking on the forum. You can create the different animations with the software, but you don't have access to the .ino file, so I can't edit the inputs and my outputs. (rpm, speed, display...)
You can easily program such function yourself, but it won't solve your problem.
Below some suggestions that might help to improve your code:
As far I see your rpmtable[ ][ ] array is contant and is not depends from rpm. In that case you shouldn't repopulate it again at every new rpm value . You can move the LED_ARRAY() function to setup() and run it only once.
At the fade loop for(int b=0; b < 255; b++) {
you change the brightness by one. This is not necessary, since the human eye is not able to distinguish such small changes. Change the brightness in steps of 2, 5 or even 10 units - this will speed up the cycle by the corresponding number of times
And one more note (it has nothing to do with speed) - if your number of diodes is #define NUMLEDS 20, why is the rpmtable size set to 32? describe the table for the required number of diodes
I have been trying to create the code as I told you but I have not been able to do it... I read the information that you posted in the post, and the truth is that I have not succeeded.
I found this example on the forum, which partly does what I want.
I don't know if you can help me more or not.
Thanks in advance.
#include <FastLED.h>
#define LED_PIN 3
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];
int Steps = 16;
int fadeAmount = -(256 / Steps); // 256 / Steps
int brightness = 0;
byte factor = 0;
int myTime = 70;
int myTime2 = 50;
//----------------------------------------------------------------------------------
void LEDcontrol(int i) {
for (int j = 0; j < Steps; j++)
{
if (i == 0 or i == 1 or i == 2 or i == 3) leds[i] = CRGB(0x006400);
if (i == 4 or i == 5) leds[i] = CRGB(0xFF0000);
if (i == 6) leds[i] = CRGB(0xFFD700);
if (i > 6) leds[i] = CRGB(0xFFD700);
brightness = brightness + fadeAmount;
leds[i].fadeLightBy(brightness);
FastLED.show();
delay(myTime);
}
}
//----------------------------------------------------------------------------------
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
//----------------------------------------------------------------------------------
void loop() {
for (int i = 0; i < NUM_LEDS; i++)
{
brightness = factor;
LEDcontrol(i);
delay(myTime2);
}
fadeAmount = -fadeAmount ;
factor = factor ^ 0xFF ;
}
How fast does your RPM change? If it's a car, then the rpm's typically can change by thousands in one second.
This means that your idea with a smooth warm-up or fade of each diode simply will not work - there is not enough time for a smooth change.
I am making an odometer and a speedometer with a hall sensor. I have little experience with interrupts...
The odometer works fine but the speedometer does not work correctly.
The size of the wheel of my vehicle is 195/45/15. If we translate that measure into linear meters the result is 1.748m.
speed = space / time.
If we count 20 pulses in a certain time (we know that the pulses are equivalent to 1,784m each) we would have the speed in m/unit of time. So, we would have the velocity.
I think the speed is wrongly calculated, also it is not updated instantly.
Could you help me??
volatile static float pulse_distance = 1.784; // in meters
volatile static float odometer;
volatile unsigned long lastPulseTime;
volatile unsigned long interval = 0;
volatile int timeoutCounter;
const int timeoutValue = 10;
volatile unsigned long dist_pulse_count;
unsigned int speed;
void setup() {
Serial.begin(115200);
attachInterrupt(0, isr, RISING);
}
void loop() {
Serial.println(odometer); //en km
speed= (pulse_distance * dist_pulse_count)*3600 / interval; // 1 sec =1000000us. 1km=1000m-> m/s measure. 1000*3.6-> km/h
Serial.println(speed);
}
void isr() {
unsigned long now = micros();
interval = now - lastPulseTime;
lastPulseTime = now;
dist_pulse_count++;
odometer+= pulse_distance;
}