Created
October 6, 2015 06:47
-
-
Save mithi/37d808e023290bdd5223 to your computer and use it in GitHub Desktop.
Calibration Code for Light Sensor Theremin
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
#include <Sparki.h> | |
int sensorLow = 80000; | |
int sensorHigh = 0; | |
int sensorValue = 0; | |
int calibrationTime = 5000; | |
void setup(){ | |
signal(3, 75); | |
int startTime = millis(); | |
int endTime = startTime + calibrationTime; | |
while (millis() < endTime){ | |
sensorValue = sparki.lightLeft(); | |
if(sensorValue > sensorHigh){ | |
sensorHigh = sensorValue; | |
} | |
if(sensorValue < sensorLow){ | |
sensorLow = sensorValue; | |
} | |
} | |
signal(10, 30); | |
displayCalibratedValues(sensorLow, sensorHigh); | |
} | |
void loop(){ | |
} | |
void signal(int n, int interval){ | |
for (int i = 0; i < n; i++){ | |
sparki.RGB(RGB_RED); | |
sparki.beep(); | |
delay(interval); | |
sparki.noBeep(); | |
sparki.RGB(RGB_OFF); | |
delay(interval); | |
} | |
} | |
void displayCalibratedValues(int sensorLow, int sensorHigh){ | |
sparki.clearLCD(); | |
sparki.println("Calibrated Values for Right Sensor:"); | |
sparki.print("lowest value:"); | |
sparki.println(sensorLow); | |
sparki.print("highest value:"); | |
sparki.println(sensorHigh); | |
sparki.updateLCD(); | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment