There is no need to add the earlier code i posted to your code, but this loop needs to change
for(int i=0; i<=255; i++){
leds[i] = CRGB(255,115,0);
FastLED.show();
delay(1);
}
It sends the signal 255 times !! Ooops.. so just change that to
for(int i=0; i<=255; i++){
leds[i] = CRGB(255,115,0);
}
FastLED.show();
this at least, but still you'll be turning off interrupts for about 4.5ms which isn't so bad as long as the minimum time between pings is less than that. (which it probably is)
Now To turn a different corner, This :float timetaken, rpm, dtime;
needs to be
volatile float rpm, timetaken;
float dtime;
timetaken is updated within one of the interrupts functions, and so is rpm.
I think you should try the suggestion i made in reply #3.
-Do the calculating as you have at the moment.
-Compare the result to any previous result so you only change the led color when you have to.
(with the for loop setting bytes in the Array) and if so, set a bool variable sendledsignal to true
-remove all calls to FastLed.show() and only call it from the interrupt if the sendledsignal is true;
I think the the idea to have the leds flash with every change of the magnet is optimistic, the magnet will probably pass to fast and i think you should get rid of the HALL_ISR all together or just use it to ping the led, but since after the magnet detect is called we may want to fire FastLED.Show() it may miss the change
All together i came to this
#include <FastLED.h>
#define LED_PIN 8
#define NUM_LEDS 256
CRGB leds[NUM_LEDS];
const int hallPin = 2;
int ledpin = 3; //LED on D3 will show blink on/off
int hallState;
float radius_of_wheel = 0.33;
volatile byte rotation;
volatile float timetaken, rpm;
volatile bool sendsignal = true;
float dtime;
int v, oldcolor = 0;
unsigned long previoustime;
int i = 0;
volatile bool ledState = LOW;
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
attachInterrupt(digitalPinToInterrupt(hallPin), magnet_detect, RISING);
attachInterrupt(digitalPinToInterrupt(hallPin), hall_ISR, CHANGE);
rotation = rpm = previoustime = 0;
pinMode(hallPin, INPUT);
pinMode(ledpin, OUTPUT);
}
void loop() {
if (millis() - dtime > 3500) //no magnet detected for 3500ms
{
rpm = v = 0;
dtime = millis();
}
digitalWrite(ledpin, ledState);
v = radius_of_wheel * rpm * 0.37699;
hallState = digitalRead(hallPin);
if (hallState == LOW) {
digitalWrite(ledpin, HIGH);
}
else {
digitalWrite(ledpin, LOW);
}
lighting();
}
void hall_ISR() {
ledState = !ledState;
}
void magnet_detect() {
if (sendsignal) {
FastLED.show();
sendsignal=false;
}
rotation++;
if (rotation >= 2)
{
timetaken = millis() - previoustime;
rpm = (1000 / timetaken) * 60;
previoustime = millis();
rotation = 0;
}
}
void lighting() {
if (v <= 7.5) {
if (oldcolor != 1) {
fill_solid(leds, NUM_LEDS, CRGB(255, 0, 0));
oldcolor = 1;
sendsignal = true;
}
}
else if (v >= 15) {
if (oldcolor != 2) {
fill_solid(leds, NUM_LEDS, CRGB(0, 255, 0));
oldcolor = 2;
sendsignal = true;
}
}
else {
if (oldcolor != 3) {
fill_solid(leds, NUM_LEDS, CRGB(255, 255, 0));
oldcolor = 3;
sendsignal = true;
}
}
}
try this.