HW 7.1 Attempt to use button timers to check for button status instead of interrupts

Dependencies:   SLCD TSI mbed

Fork of slider_diatonic_v1 by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
bomalley
Date:
Wed Feb 25 18:28:52 2015 +0000
Parent:
3:f68e9cdfaf2d
Commit message:
HW 7.1

Changed in this revision

mbed.bld Show annotated file Show diff for this revision Revisions of this file
slider_diatonic_v1.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/mbed.bld	Wed Feb 18 15:27:17 2015 +0000
+++ b/mbed.bld	Wed Feb 25 18:28:52 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file
--- 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();
         }