Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lightResistor;
- bool calibrate_is_finished = false;
- int threshold;
- void setup() {
- threshold = calibrateLightSensor(lightResistor);
- }
- void loop() {
- if (checkThreshold(readSensor, 120)) {
- //Lightshow
- }
- }
- int readSensor(int sensorPin) {
- return analogRead(sensorPin);
- }
- int calibrateLightSensor(int sensorPin) {
- int maxValue = 0;
- int minValue = 1023;
- while (!calibrate_is_finished) {
- int readValue = readSensor(lightResistor);
- if (readValue > maxValue) maxValue = readValue;
- if (readValue < maxValue) minValue = readValue;
- }
- }
- bool checkThreshold(int value, int threshold) {
- if (value > threshold) {
- return true;
- }
- else if (value < threshold) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement