Can't figure out this one, my Multi-dimensional Array doesn't work.
Fork of slider_diatonic_v1_HW6_2-ChangingOctaves by
Revision 5:d7747f156e9a, committed 2015-02-25
- Comitter:
- destradafilm
- Date:
- Wed Feb 25 17:04:35 2015 +0000
- Parent:
- 4:de991c90af6a
- Commit message:
- HW_7_1 - Using two timers
Changed in this revision
slider_diatonic_v1.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r de991c90af6a -r d7747f156e9a slider_diatonic_v1.cpp --- a/slider_diatonic_v1.cpp Mon Feb 23 04:49:39 2015 +0000 +++ b/slider_diatonic_v1.cpp Wed Feb 25 17:04:35 2015 +0000 @@ -6,7 +6,8 @@ #define CHANNELON 0 #define CHANNELOFF 1 #define LCDLEN 10 -#define DATATIME 100 //milli seccnds +#define DATATIME 50 //milli seccnds +#define PUSHTIME 100 // MS //LCD messages @@ -21,24 +22,31 @@ #define TONEAST 1 #define NUMTONES 10 #define LEDPERIOD 0.001 +#define OCTAVESTATE 1 +#define NUMOCTS 2 //#define PRINTDEBUG 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 diatonicScale2[NUMTONES] ={493.88, 523.25,587.33,659.25,698.46,783.99,880.00,987.77,1046.50,1174.66}; +int octaveState = 0; +float diatonicScale[OCTAVESTATE][NUMTONES] = {{246.94, 261.63,293.66,329.63,349.23,392.00,440.00,493.88,523.25,587.33}, + {493.88, 523.25,587.33,659.25,698.46,783.99,880.00,987.77,1046.50,1174.66}}; +//float diatonicScale2[NUMTONES] =; SLCD slcd; //define LCD display TSISensor tsiScaling; // Capacitive sensor/slider // changes -DigitalIn RtButton(PTC3); // make RIGHT button interrrupt +DigitalOut RtButton(PTC3); // make RIGHT button interrrupt int RtbuttonState; // switch changes when RtButton is pressed PwmOut led(LED_RED); DigitalOut outPin(PTC9); //J1-16 PwmOut soundOut(PTA13); -Timer dataTimer; + + +Timer dataTimer; // timer - check if slider has been changed every DATATIME (50ms) +Timer buttonTimer; // check if button has been pressed every PUSHTIME (100ms) // Global scalars char lcdData[LCDLEN]; @@ -53,19 +61,20 @@ slcd.printf(lMess); } -void diatonicAdjust( float scaling) { +void diatonicAdjust( float scaling, float octfactors[octaveState]) { int tempInt; int scaleIndex; static int oldScaleIndex = 0; + /* There appears to be a set up time for setting the PWM time period only do a nes set up if the indext changes. */ scaleIndex = (int)(NUMTONES * scaling); if (scaleIndex != oldScaleIndex) { if(RtbuttonState == false){ - toneFreq = diatonicScale[scaleIndex]; + toneFreq = diatonicScale[0][scaleIndex]; } else { - toneFreq = diatonicScale2[scaleIndex]; + toneFreq = diatonicScale[1][scaleIndex]; } tonePeriod = 1.0/toneFreq; soundOut.period(tonePeriod); // adjusting period @@ -103,23 +112,36 @@ tempInt = (int)toneFreq; sprintf (lcdData,"%4d",tempInt); LCDMessNoDwell(lcdData); + // Start data timer dataTimer.start(); dataTimer.reset(); + + buttonTimer.start(); + buttonTimer.reset(); while (true) { - - RtbuttonState = RtButton; // button is pulled up so false is when button is pushed it's inverted to avoid confusion downstream + + if(buttonTimer.read_ms() > PUSHTIME){ +//HANDLE USER INPUT FOR DISPLAY SECTIONS +// + RtbuttonState = !RtButton; // button is pulled up so false is when button is pushed it's inverted to avoid confusion downstream + if(RtbuttonState) { + octaveState++; + octaveState = octaveState % NUMOCTS; + } + buttonTimer.reset(); if (dataTimer.read_ms() > DATATIME){ // check to see if enough time has passed // to read the touch pad tempValue = tsiScaling.readPercentage(); if(tempValue > 0) { // soundOut.write(TONEON); // set duty factor to 50% - diatonicAdjust(tempValue); + diatonicAdjust(tempValue, octfactors[octaveState]); lightAdjust(tempValue); } else { soundOut.write(TONEOFF); // set dutyfactor to 0% + sprintf (lcdData, "%4d", octaveState + 1);// just to make thigns user readable LCDMessNoDwell("SOFF"); } dataTimer.reset();