Create a gist now

Instantly share code, notes, and snippets.

Calibration Code for Light Sensor Theremin
#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