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.
Dependencies: TextLCD mbed MMA8451Q TSI
Diff: main.cpp
- Revision:
- 9:f1fa0dad4096
- Parent:
- 8:60231840370f
- Child:
- 10:6e18b220e10c
--- a/main.cpp Sat Sep 19 10:04:37 2015 +0000
+++ b/main.cpp Wed Sep 23 15:38:04 2015 +0000
@@ -10,10 +10,11 @@
#define METRONOME 2
#define TILT_TOLERANCE_SET 0.75
#define TILT_TOLERANCE_RESET 0.05
-#define MIN_METRONOME_BPM 40
-#define MAX_METRONOME_BPM 208
-#define MIN_OCTAVE 1
-#define MAX_OCTAVE 8
+#define MIN_METRONOME_BPM 30
+#define MAX_METRONOME_BPM 185
+#define INTERVAL_METRONOME_BPM 5
+#define MIN_OCTAVE 2
+#define MAX_OCTAVE 6
#define MMA8451_I2C_ADDRESS (0x1d<<1)
TextLCD lcd(PTE5, PTE3, PTE2, PTB11, PTB10, PTB9, TextLCD::LCD16x2); //TextLCD (PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type=LCD16x2, PinName bl=NC, PinName e2=NC, LCDCtrl ctrl=HD44780)
@@ -25,10 +26,10 @@
int freq;
int multiplier =0;
bool doDiesis=false;
+int bpm = 60;
Note LA4(440, true, &multiplier, &doDiesis);
Note MI4(330, true, &multiplier, &doDiesis);
-//Note FA4(349, true, &multiplier, &doDiesis);
void volumeSettings(float* volume)
{
@@ -64,23 +65,25 @@
led1=!led1;
}
-void metronomeSettings()
+void metronomeSettings(int* bpmReg)
{
- float bpm=6;
+ float t_bpm = *bpmReg;
lcd.cls();
- lcd.printf("bpm: %.0f",bpm*10);
- wait(0.1);
+ lcd.printf("bpm: %d", bpm);
+ wait(0.2);
float tmp = slider.readPercentage();
if(tmp>0) {
t.detach();
while (tmp>0) {
- bpm = MIN_METRONOME_BPM/10+tmp*(MAX_METRONOME_BPM-MIN_METRONOME_BPM)/10;
+ t_bpm =int((MIN_METRONOME_BPM+tmp*(MAX_METRONOME_BPM-MIN_METRONOME_BPM))/INTERVAL_METRONOME_BPM);
tmp = slider.readPercentage();
lcd.cls();
- lcd.printf("bpm: %.0f",bpm*10);
+ lcd.printf("bpm: %.0f",t_bpm*INTERVAL_METRONOME_BPM);
wait(0.1);
}
- t.attach(&flipLed, 6/(bpm));
+ *bpmReg=(int(t_bpm))*INTERVAL_METRONOME_BPM;
+ t.attach(&flipLed, 60.0/(*bpmReg));
+
}
}
@@ -118,11 +121,9 @@
t.attach(&flipLed, 1.0);
-
while (true) {
lcd.cls();
menuManager(&mode, &allowEdit);
- lcd.printf("f=%.3f, d=%d", speaker.getFreq(), doDiesis);
wait(0.1);
switch(mode) {
case PLAY:
@@ -132,11 +133,10 @@
volumeSettings(volume);
break;
case METRONOME:
- metronomeSettings();
+ metronomeSettings(&bpm);
break;
default:
mode=PLAY;
}
-
}
}
\ No newline at end of file
