light sensor theremin (right, center, left) for sparki
This file contains 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> | |
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