Created
September 23, 2012 23:09
-
-
Save ktzar/3773388 to your computer and use it in GitHub Desktop.
Reading from a light sensor
This file contains hidden or 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
int sensorValue = 0; | |
int outputValue = 0; | |
int previousValue = 0; | |
const int threshold = 30; | |
const int analogInPin = A0; | |
void setup() { | |
// initialise serial: | |
Serial.begin(9600); | |
} | |
void loop() { | |
sensorValue = analogRead(analogInPin); | |
outputValue = map(sensorValue, 4, 70, 0, 255); | |
if (outputValue - previousValue > threshold || outputValue - previousValue < -threshold) { | |
previousValue = outputValue; | |
Serial.println(outputValue); | |
delay(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment