Skip to content

Instantly share code, notes, and snippets.

@ktzar
Created September 23, 2012 23:09
Show Gist options
  • Save ktzar/3773388 to your computer and use it in GitHub Desktop.
Save ktzar/3773388 to your computer and use it in GitHub Desktop.
Reading from a light sensor
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