Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of slider_diatonic_v1 by
Diff: slider_diatonic_v1.cpp
- Revision:
- 4:d59d946649b8
- Parent:
- 3:f68e9cdfaf2d
- Child:
- 5:c047f46f8726
diff -r f68e9cdfaf2d -r d59d946649b8 slider_diatonic_v1.cpp --- a/slider_diatonic_v1.cpp Wed Feb 18 15:27:17 2015 +0000 +++ b/slider_diatonic_v1.cpp Sun Feb 22 07:57:45 2015 +0000 @@ -9,7 +9,7 @@ #define DATATIME 100 //milli seccnds //LCD messages - +#define TONEARRAY // Operating parameters #define SIDETONE 700.0 @@ -26,11 +26,12 @@ Serial pc(USBTX, USBRX); float diatonicScale[NUMTONES] = {246.94, 261.63,293.66,329.63,349.23,392.00,440.00,493.88,523.25,587.33}; +float diatonicScaleOctave[NUMTONES] = {659.25, 698.46, 783.99, 880.00, 987.77, 1046.50, 1174.66, 1318.51, 1396.91, 1567.98 }; SLCD slcd; //define LCD display TSISensor tsiScaling; // Capacitive sensor/slider - +InterruptIn mybutton(PTC3); //push botton with internal pullup PwmOut led(LED_RED); DigitalOut outPin(PTC9); //J1-16 PwmOut soundOut(PTA13); @@ -41,8 +42,15 @@ float tonePeriod; float toneFreq = SIDETONE; +// Int used to switch between different octave +int relayState = CHANNELOFF; +void pressed() // button intterupt +{ + relayState = !relayState; +} + void LCDMessNoDwell(char *lMess){ slcd.Home(); slcd.clear(); @@ -58,7 +66,10 @@ */ scaleIndex = (int)(NUMTONES * scaling); if (scaleIndex != oldScaleIndex) { - toneFreq = diatonicScale[scaleIndex]; + if (relayState == CHANNELOFF) + toneFreq = diatonicScale[scaleIndex]; + else + toneFreq = diatonicScaleOctave[scaleIndex]; tonePeriod = 1.0/toneFreq; soundOut.period(tonePeriod); // adjusting period soundOut.write(TONEON); // there is a setup time for both period and DF @@ -74,6 +85,9 @@ LCDMessNoDwell(lcdData); return; } + + + void lightAdjust( float scaling) { // Control brightness of LED float tempDutyFactor; @@ -84,13 +98,14 @@ int main(){ int tempInt; - float tempValue; - + float tempValue; tonePeriod = 1.0/toneFreq; soundOut.period(tonePeriod); led.period(tonePeriod); led.write(CHANNELOFF); outPin.write(CHANNELOFF); + // set up interrrupts to be used later for taps + mybutton.fall(&pressed); tempInt = (int)toneFreq; sprintf (lcdData,"%4d",tempInt);