user33369: I'm trying to make a lamp that fades when it reacts with surrounding light. I've installed a library from github  that doesn't require the delay (). The serial monitor doesn't refresh.
The lamp is supposed to fade from 0-255 when in the dark and fade 255-0 when in light. It's supposed to happen only once so I can't put it in loop().
The LED is connected to PWM pin 10. The LDR sensor is connected to A0.
#include <LEDFader.h>
int sensorvalue = analogRead(A0);
LEDFader led = LEDFader(10);

void setup(){

  if(sensorvalue<=380){    
    led.set_value(0);
    led.fade(255, 3000);
  }
  if(sensorvalue>=555){
    led.set_value(255);
    led.fade(0,3000);
  }
}

void loop() {
  Serial.begin(9600);
  Serial.println(sensorvalue);
  led.update();

}

user4169: Arduino does not work that way. You only try to read a sensor value outside of a function, so will happen once only, if it works at all. You need to read the sensor more often and always read from within a function.
Serial.begin() is used once when the code starts, so that will be in the setup()
Your LED fade values are only set one time, when the cpu starts because you have the fade in the setup(). 
In the following example we do all fade code in the loop() but change the fade values only when the sensor reading changes.
#include <LEDFader.h>
LEDFader led = LEDFader(10);

int sensorValue = 0;
int sensorValueLast = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);

        if (sensorValueLast!=sensorValue)
        {
          sensorValueLast = sensorValue;        
          if(sensorvalue<=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue>=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }
        }

  led.update();     
}

This example only calls led.fade() when the sensor value changes but uses the same sensor reading that was found during startup. The sensor is read just once time and the fade values are set just one time.
#include <LEDFader.h>
LEDFader led = LEDFader(10);

int sensorValue = 0;
int sensorValueLast = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);

        if (sensorValueLast!=sensorValue)
        {
          sensorValueLast = sensorValue;        
          if(sensorvalue<=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue>=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }

          led.update();     
        }
}

This example does everything just one time, when the cpu starts
#include <LEDFader.h>
LEDFader led = LEDFader(10);

int sensorValue = 0;

void setup()
{
   Serial.begin(9600);

   sensorValue = analogRead(A0);
   Serial.println(sensorValue);

          if(sensorvalue<=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue>=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }

          led.update();     

}

void loop()
{
   //we will always see the same value
   Serial.println(sensorValue);
}


33369: <p>I'm trying to make a lamp that fades when it reacts with surrounding light. I've installed a library from github  that doesn't require the delay (). The serial monitor doesn't refresh.
The lamp is supposed to fade from 0-255 when in the dark and fade 255-0 when in light. It's supposed to happen only once so I can't put it in loop().</p>

<p>The LED is connected to PWM pin 10. The LDR sensor is connected to A0.</p>

<pre><code>#include &lt;LEDFader.h&gt;
int sensorvalue = analogRead(A0);
LEDFader led = LEDFader(10);

void setup(){

  if(sensorvalue&lt;=380){    
    led.set_value(0);
    led.fade(255, 3000);
  }
  if(sensorvalue&gt;=555){
    led.set_value(255);
    led.fade(0,3000);
  }
}

void loop() {
  Serial.begin(9600);
  Serial.println(sensorvalue);
  led.update();
</code></pre>

<p>}</p>
 4169: <p>Arduino does not work that way. You only try to read a sensor value outside of a function, so will happen once only, if it works at all. You need to read the sensor more often and always read from within a function.</p>

<p><code>Serial.begin()</code> is used once when the code starts, so that will be in the setup()</p>

<p>Your LED fade values are only set one time, when the cpu starts because you have the fade in the <code>setup()</code>. </p>

<p>In the following example we do all fade code in the <code>loop()</code> but change the fade values only when the sensor reading changes.</p>

<pre><code>#include &lt;LEDFader.h&gt;
LEDFader led = LEDFader(10);

int sensorValue = 0;
int sensorValueLast = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);

        if (sensorValueLast!=sensorValue)
        {
          sensorValueLast = sensorValue;        
          if(sensorvalue&lt;=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue&gt;=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }
        }

  led.update();     
}
</code></pre>

<p>This example only calls <code>led.fade()</code> when the sensor value changes but uses the same sensor reading that was found during startup. The sensor is read just once time and the fade values are set just one time.</p>

<pre><code>#include &lt;LEDFader.h&gt;
LEDFader led = LEDFader(10);

int sensorValue = 0;
int sensorValueLast = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);

        if (sensorValueLast!=sensorValue)
        {
          sensorValueLast = sensorValue;        
          if(sensorvalue&lt;=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue&gt;=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }

          led.update();     
        }
}
</code></pre>

<p>This example does everything just one time, when the cpu starts</p>

<pre><code>#include &lt;LEDFader.h&gt;
LEDFader led = LEDFader(10);

int sensorValue = 0;

void setup()
{
   Serial.begin(9600);

   sensorValue = analogRead(A0);
   Serial.println(sensorValue);

          if(sensorvalue&lt;=380)
          {    
             led.set_value(0);
             led.fade(255, 3000);
          }
          if(sensorvalue&gt;=555)
          {
            led.set_value(255);
            led.fade(0,3000);
          }

          led.update();     

}

void loop()
{
   //we will always see the same value
   Serial.println(sensorValue);
}
</code></pre>
