Big newbie here. Basically I'm trying to take the example listed on: Arduino Playground - PhotoResistor and do the opposite behavior with it. Meaning when the resistor value is lower, the LED is also lower. Bright light in = bright LED. Been playing around with it for a while and can't seem to get it to work. Any suggestions?
int prmin = 600;
int prmax = 1000;
int lightPin = A0;
int ledPin=11;
void setup()
{
Serial.begin(9600);
pinMode( lightPin, INPUT);
pinMode( ledPin, OUTPUT );
}
void loop()
{
// input voltage on A0 of 2.5v to 3.3v, clamp and map to an appropriate range
// step 1: read A0
int val = analogRead(lightPin);
// step 2: constrain it to our expected range (based on MATH)
val = constrain(val, prmin, prmax);
// step 3: map the range [511, 675] to the range [0, 255]
val = map(val, prmin, prmax, 0, 255);
// step 4: write the result out to the pwm pin
analogWrite(ledPin, val);
// step 5: diagnostic println()
Serial.println(val);
}