HW 6.2 Spring 2015 NMHU New Mexico Highlands. Changing Octaves on KL tap sensor project.
Fork of slider_diatonic_v1 by
Diff: slider_diatonic_v1.cpp
- Revision:
- 4:761f247c603e
- Parent:
- 3:f68e9cdfaf2d
--- a/slider_diatonic_v1.cpp Wed Feb 18 15:27:17 2015 +0000 +++ b/slider_diatonic_v1.cpp Mon Feb 23 06:08:03 2015 +0000 @@ -9,7 +9,10 @@ #define DATATIME 100 //milli seccnds //LCD messages - +//Button +#define BUTOFF 1 +#define BUTON 0 +#define BUTTON PTC3 // Operating parameters #define SIDETONE 700.0 @@ -21,10 +24,14 @@ #define TONEAST 1 #define NUMTONES 10 #define LEDPERIOD 0.001 + +#define OCTAVECHANGE 2 //double to increase frequency //#define PRINTDEBUG Serial pc(USBTX, USBRX); +InterruptIn myButton(BUTTON);//button to change octaves + float diatonicScale[NUMTONES] = {246.94, 261.63,293.66,329.63,349.23,392.00,440.00,493.88,523.25,587.33}; SLCD slcd; //define LCD display @@ -41,7 +48,7 @@ float tonePeriod; float toneFreq = SIDETONE; - +int buttonState = BUTOFF; void LCDMessNoDwell(char *lMess){ slcd.Home(); @@ -58,7 +65,14 @@ */ scaleIndex = (int)(NUMTONES * scaling); if (scaleIndex != oldScaleIndex) { - toneFreq = diatonicScale[scaleIndex]; + if(buttonState == BUTON) + { + toneFreq = diatonicScale[scaleIndex * OCTAVECHANGE]; + } + else + { + toneFreq = diatonicScale[scaleIndex]; + } tonePeriod = 1.0/toneFreq; soundOut.period(tonePeriod); // adjusting period soundOut.write(TONEON); // there is a setup time for both period and DF @@ -82,6 +96,11 @@ return; } +void pressed() +{ + buttonState = !buttonState; +} + int main(){ int tempInt; float tempValue; @@ -98,8 +117,9 @@ // Start data timer dataTimer.start(); dataTimer.reset(); - + while (true) { + myButton.fall(&pressed); if (dataTimer.read_ms() > DATATIME){ // check to see if enough time has passed // to read the touch pad tempValue = tsiScaling.readPercentage();