Skip to content

Instantly share code, notes, and snippets.

@mithi
Last active October 10, 2015 02:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mithi/f371ff088e1f1f373665 to your computer and use it in GitHub Desktop.
light sensor theremin (right, center, left) for sparki
#include <Sparki.h>
const int RIGHT = 0;
const int CENTER = 1;
const int LEFT = 2;
const int freqA = 440;
const int freqF = 370;
const int freqmidC = 261;
const int countMax = 500;
const int delayPerBeep = 10;
const int maxPitchCount = 15;
int state = 0;
void setup(){
}
void play(int sensorValue, int sensorLow, int sensorHigh, int freq){
int pitchMultiplier = map(sensorValue, sensorLow, sensorHigh, 1, maxPitchCount);
sparki.beep(pitchMultiplierr*freq);
display(state, sensorValue);
delay(delayPerBeep);
}
void display(int state, int val){
sparki.clearLCD();
sparki.print("state: ");
sparki.println(state);
sparki.print("sensor value: ");
sparki.println(val);
sparki.print("counts left:");
sparki.println(countMax - count);
sparki.updateLCD();
}
void loop(){
for(int count = 0; count < countMax; count++){
if( state == RIGHT){
sparki.RGB(RGB_RED);
play(sparki.lightRight(), 30, 368, freqmidC);
}
if( state == CENTER){
sparki.RGB(RGB_YELLOW);
play(sparki.lightCenter(), 10, 239, freqF);
}
if( state == LEFT){
sparki.RGB(RGB_GREEN);
play(sparki.lightLeft(), 21, 349, freqA);
}
}
state++;
if (state >= 3){
state = RIGHT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment