lisa (owner)

Revisions

gist: 213017 Download_button fork
public
Public Clone URL: git://gist.github.com/213017.git
Embed All Files: show embed
Arduino LDR LED dimmer.cpp #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define SENSORPIN 0
#define PWMPIN 3
 
int sensorMax = -1;
int sensorMin = 1024;
 
void setup() { }
 
void loop() {
  delay(10);
  analogWrite(PWMPIN,readLDRValue());
}
 
/*
* Returns the value of the LDR on the scale of 0-255
* Needs defined:
* * SENSORPIN (pin onto which LDR is connected)
* * PWMPIN (PWM pin onto which the LED/output is connected)
*
*/
int readLDRValue() {
  int sensorValue = 0; // variable to store the value coming from the sensor
 
   sensorValue = map(analogRead(SENSORPIN),0,1023,0,255);
  
  if (sensorValue > sensorMax)
    sensorMax = sensorValue;
  if (sensorValue < sensorMin)
   sensorMin = sensorValue;
  return sensorValue;
}