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
Revision 4:19a67d6e47be, committed 2015-02-23
- Comitter:
- rahulpatle101
- Date:
- Mon Feb 23 04:17:35 2015 +0000
- Parent:
- 3:f68e9cdfaf2d
- Commit message:
- HW 6.2
Changed in this revision
slider_diatonic_v1.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f68e9cdfaf2d -r 19a67d6e47be slider_diatonic_v1.cpp --- a/slider_diatonic_v1.cpp Wed Feb 18 15:27:17 2015 +0000 +++ b/slider_diatonic_v1.cpp Mon Feb 23 04:17:35 2015 +0000 @@ -25,9 +25,13 @@ Serial pc(USBTX, USBRX); +//diatonicScaleOcrave Values +float diatonicScaleOctave[NUMTONES] = {659.25, 698.46, 783.99, 880.00, 987.77, 1046.50, 1174.66, 1318.51, 1396.91, 1567.98 }; 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 + +InterruptIn pushButton(PTC3); //interrupt push botton PTC3 with internal pullup TSISensor tsiScaling; // Capacitive sensor/slider @@ -41,6 +45,9 @@ float tonePeriod; float toneFreq = SIDETONE; +// Set the state. +int relayState = CHANNELOFF; + void LCDMessNoDwell(char *lMess){ @@ -48,7 +55,14 @@ slcd.clear(); slcd.printf(lMess); } - + + +// PTC3 tap button intterupt to switch the octave +void pressed() +{ + relayState = !relayState; +} + void diatonicAdjust( float scaling) { int tempInt; int scaleIndex; @@ -59,6 +73,14 @@ scaleIndex = (int)(NUMTONES * scaling); if (scaleIndex != oldScaleIndex) { toneFreq = diatonicScale[scaleIndex]; + //set the if loop to set the different octaves dependent on the current state + 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 @@ -92,6 +114,9 @@ led.write(CHANNELOFF); outPin.write(CHANNELOFF); + // Interupt for tap button + pushButton.fall(&pressed); + tempInt = (int)toneFreq; sprintf (lcdData,"%4d",tempInt); LCDMessNoDwell(lcdData);