I have a code (below) that reacts to the proximity of a person, so the less light the LDR recieves (the closer you get), the dimmer the LED gets.
The more light the LDR receives, the brighter it gets.
I simply want to reverse this function, so that the closer you get to the LDR (the less light it recieves), the brighter the LED shines.
When the LDR receives lots of light, I want the LED to be dimm, (or in the future blinking at a slow rate!)
Does anyone know how to simply reverse this function of the LDR, here is the code:
//Example 06B: Blink LED at a rate specified by the analogue input
#define LED 9 // the pin for the LED
int val = 0; // variable used to store the value coming from the sensor
void setup() {
pinMode(LED, OUTPUT); //LED is as an OUTPUT
// Note: Analogue pins are automatically set as inputs..
}
void loop() {
val = analogRead(0); // read the value from the sensor
analogWrite(LED, val/4); // turn the LED on at the brightness set by the sensor