No, I was thinking of something much simpler: (uncompiled, untested)
const int SensorA = 0;
const int ledPin = 2; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
int sensor_val = analogRead(SensorA);
Serial.print("Value from sensor");
Serial.println( sensor_val );
if (sensor_val > 850){
Serial.print("not enough");
interval = 100;
} else if ((sensor_val < 850) && (sensor_val > 500)) {
Serial.print("good");
interval = 500;
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
ledState = 1 - ledState;
digitalWrite(ledPin, ledState);
}
}
Not sure exactly what blink rate you want, but hopefully, you get the idea.