![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
HW 7.1 Attempt to use button timers to check for button status instead of interrupts
Fork of slider_diatonic_v1 by
Diff: slider_diatonic_v1.cpp
- Revision:
- 4:922d6f8fe95f
- Parent:
- 3:f68e9cdfaf2d
--- a/slider_diatonic_v1.cpp Wed Feb 18 15:27:17 2015 +0000 +++ b/slider_diatonic_v1.cpp Wed Feb 25 18:28:52 2015 +0000 @@ -23,6 +23,13 @@ #define LEDPERIOD 0.001 //#define PRINTDEBUG +#define NUMOCTS 1 +//Button --> +#define BUTOFF 1 +#define BUTON 0 +#define BUTTON PTC3 +#define PUSHTIME 1000 //wait to check for button press + 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}; @@ -41,7 +48,16 @@ float tonePeriod; float toneFreq = SIDETONE; +//Timers--> +Timer buttonTimer;//checks for button state change after set amout of time. +//buttons --> + +int LButtonState = BUTOFF; //Set the button state to off +DigitalIn LftButton(BUTTON); //PTC3 + +//Octave changer --> +int octaveState = NUMOCTS; //Not sure what value this should be void LCDMessNoDwell(char *lMess){ slcd.Home(); @@ -98,8 +114,20 @@ // Start data timer dataTimer.start(); dataTimer.reset(); - + buttonTimer.start(); //checks for button state change after set amout of time. + buttonTimer.reset(); + while (true) { + + if(buttonTimer.read_ms() > PUSHTIME) { + //check button first + LButtonState = !LftButton; //button is off or on + if(LButtonState) { + octaveState++; + octaveState = octaveState % NUMOCTS; + } + } + if (dataTimer.read_ms() > DATATIME){ // check to see if enough time has passed // to read the touch pad tempValue = tsiScaling.readPercentage(); @@ -109,7 +137,8 @@ lightAdjust(tempValue); } else { soundOut.write(TONEOFF); // set dutyfactor to 0% - LCDMessNoDwell("SOFF"); + sprintf(lcdData, "%4d", octaveState + 1); + LCDMessNoDwell("lcdData"); } dataTimer.reset(); }