Michele Furlanetto / Mbed 2 deprecated mbed_keyboard

Dependencies:   TextLCD mbed MMA8451Q TSI

Files at this revision

API Documentation at this revision

Comitter:
mfurlanetto
Date:
Mon Oct 26 14:38:00 2015 +0000
Branch:
mono
Parent:
16:b3cc7cf41a1b
Commit message:
risolto bug di visualizzazione.

Changed in this revision

MyLCD.cpp Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MyLCD.cpp	Mon Oct 26 13:20:14 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-#include "mbed.h"
-#include "TextLCD.h"
-#include <string>
-#ifndef MYLCD
-#define MYLCD
-class MyLCD
-{
-public:
-    MyLCD(int refreshRate, PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7): lcd(rs, e, d4, d5, d6, d7) {
-        bufferOld[0]='\0';
-        if (refreshRate>0)
-            t.attach(this, &MyLCD::update, 1.0/refreshRate);
-        else
-            t.attach(this, &MyLCD::update, 1.0/20);
-    }
-    
-    void printf(string text) {
-        text.copy(buffer, 32, 0 );
-        buffer[32]='\0';
-    }
-    
-    void printf(string text, float number, string nav) {
-        char tmp2[33];
-        sprintf(tmp2,text.append(": %.0f\n%s\0").c_str(), number, nav);
-        printf(tmp2);
-    }
-
-private:
-    TextLCD lcd;
-    Ticker t;
-    char buffer[33], bufferOld [33];
-
-    void update() {
-        if(!strcmp(bufferOld,buffer)==0) {
-            lcd.cls();
-            lcd.printf("%s\0", buffer);
-            strncpy(bufferOld, buffer, 32);
-        }
-    }
-};
-
-#endif
\ No newline at end of file
--- a/main.cpp	Mon Oct 26 13:20:14 2015 +0000
+++ b/main.cpp	Mon Oct 26 14:38:00 2015 +0000
@@ -28,24 +28,14 @@
 int freq;
 int multiplier =0;
 int bpm = 60;
-    bool allowEdit=false;
-    int mode=OCTAVE;
-    
-//string lcdBuffer;
-//string lcdBufferCache;
-void volumeSettings(float* volume)
-{
-    float tmp= slider.readPercentage();
-    if (tmp>0) *volume = tmp;
-    //lcdBuffer=
-    lcd.printf("VOLUME: %.0f\n%s", (*volume)*10,"<ottave     bpm>");
-}
+bool allowEdit=false;
+int mode=OCTAVE;
+
 
 void menuManager()
 {
     double y=acc.getAccY();
     if (allowEdit==false) {
-        //lcd.printf("incl: ", y,"");
         if (y<-TILT_TOLERANCE_SET) {
             allowEdit=true;
             mode=mode+1;
@@ -76,14 +66,17 @@
 void metronomeSettings(int* bpmReg)
 {
     float t_bpm = *bpmReg;
-    lcd.printf("BPM: %.0f\n%s", bpm ,"<volume  ottave>");
+    lcd.printf("BPM: %d\n<volume  ottave>", bpm );
+    wait(0.1);
     float tmp = slider.readPercentage();
     if(tmp>0) {
         tLedOn.detach();
         while (tmp>0) {
             t_bpm =int((MIN_METRONOME_BPM+tmp*(MAX_METRONOME_BPM-MIN_METRONOME_BPM))/INTERVAL_METRONOME_BPM);
             tmp = slider.readPercentage();
-            lcd.printf("BPM %.0f\n%s",t_bpm*INTERVAL_METRONOME_BPM,"<volume  ottave>");
+            lcd.cls();
+            lcd.printf("BPM: %.0f\n<volume  ottave>",t_bpm*INTERVAL_METRONOME_BPM);
+            wait(0.1);
         }
         *bpmReg=(int(t_bpm))*INTERVAL_METRONOME_BPM;
         tLedOn.attach(&ledOn, 60.0/(*bpmReg));
@@ -91,9 +84,24 @@
 }
 
 
+void volumeSettings(float* volume)
+{
+    lcd.printf("VOLUME: %.0f\n%s", (*volume)*10,"<ottave     bpm>");
+    wait(0.1);
+    float tmp= slider.readPercentage();
+    if (tmp>0) {
+        *volume = tmp;
+        lcd.cls();
+        lcd.printf("VOLUME: %.0f\n%s", (*volume)*10,"<ottave     bpm>");
+        wait(0.1);
+    }
+}
+
 void octaveSettings()
 {
-    lcd.printf("OTTAVA %.0f\n%s",multiplier+4,"        volume>");
+    
+    lcd.printf("OTTAVA %d  \n         volume>",multiplier+4);
+    wait(0.1);
     float octave=4;
     float tmp = slider.readPercentage();
     if(tmp>0) {
@@ -101,7 +109,9 @@
             octave = MIN_OCTAVE+tmp*(MAX_OCTAVE-MIN_OCTAVE);
             multiplier=((int)octave)-4;
             tmp = slider.readPercentage();
-            lcd.printf("OTTAVA %.0f\n%s",octave,"         volume>");
+            lcd.cls();
+            lcd.printf("OTTAVA %.0f  \n         volume>",octave);
+            wait(0.1);
         }
     }
 }
@@ -132,8 +142,8 @@
     ButtonMusical g (PTD2, SI4, &speaker);
 
     while (true) {
+        lcd.cls();
         menuManager();
-lcd.cls();
         switch(mode) {
             case OCTAVE:
                 octaveSettings();
@@ -148,6 +158,5 @@
                 mode=OCTAVE;
                 break;
         }
-wait(0.1);        
     }
 }
\ No newline at end of file