A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:a7a43371b306 1 #pragma once
ram54288 0:a7a43371b306 2
ram54288 0:a7a43371b306 3 #include "mbed.h"
ram54288 0:a7a43371b306 4
ram54288 0:a7a43371b306 5 class metronome
ram54288 0:a7a43371b306 6 {
ram54288 0:a7a43371b306 7 public:
ram54288 0:a7a43371b306 8 enum { beat_samples = 30 };
ram54288 0:a7a43371b306 9
ram54288 0:a7a43371b306 10 public:
ram54288 0:a7a43371b306 11 metronome()
ram54288 0:a7a43371b306 12 : m_timing(false), m_beat_count(0) {}
ram54288 0:a7a43371b306 13 ~metronome() {}
ram54288 0:a7a43371b306 14
ram54288 0:a7a43371b306 15 public:
ram54288 0:a7a43371b306 16 // Call when entering "learn" mode
ram54288 0:a7a43371b306 17 void start_timing();
ram54288 0:a7a43371b306 18 // Call when leaving "learn" mode
ram54288 0:a7a43371b306 19 void stop_timing();
ram54288 0:a7a43371b306 20
ram54288 0:a7a43371b306 21 // Should only record the current time when timing
ram54288 0:a7a43371b306 22 // Insert the time at the next free position of m_beats
ram54288 0:a7a43371b306 23 void tap();
ram54288 0:a7a43371b306 24
ram54288 0:a7a43371b306 25 bool is_timing() const { return m_timing; }
ram54288 0:a7a43371b306 26 // Calculate the BPM from the deltas between m_beats
ram54288 0:a7a43371b306 27 // Return 0 if there are not enough samples
ram54288 0:a7a43371b306 28 size_t get_bpm() const;
ram54288 0:a7a43371b306 29
ram54288 0:a7a43371b306 30 private:
ram54288 0:a7a43371b306 31 bool m_timing;
ram54288 0:a7a43371b306 32 Timer m_timer;
ram54288 0:a7a43371b306 33
ram54288 0:a7a43371b306 34 // Insert new samples at the end of the array, removing the oldest
ram54288 0:a7a43371b306 35 size_t m_beats[beat_samples];
ram54288 0:a7a43371b306 36 size_t m_beat_count;
ram54288 0:a7a43371b306 37 };