Created
October 19, 2009 01:52
-
-
Save lisa/213017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Lisa,
Just want to check if the lines should not have the value assignment swapped around?:
if (sensorValue > sensorMax)
sensorValue = sensorMax;
if (sensorValue < sensorMin)
sensorValue = sensorMin;