Test program for BaseMachineUIController Library
Dependencies: AverageAnalogIn BaseMachineUIController ExioBufferdController MCP23S17 PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD AT24C1024
Diff: main.cpp
- Revision:
- 2:354ca389e975
- Parent:
- 1:46e088b12083
- Child:
- 3:97e89dad2a44
--- a/main.cpp Sun Nov 06 23:03:08 2016 +0000 +++ b/main.cpp Sun Nov 06 23:25:33 2016 +0000 @@ -14,21 +14,36 @@ #define UART_TRACE (0) #include "BaseMachineUIController.h" +const int samplingRate = 1; + BaseMachineUIController UIController; uint8_t step = 0; int isStepChanged = false; bool isRunning = false; +int bpm = 125; +uint32_t tick = 0; +int noteLen; + +void setNoteLen() +{ + noteLen = 15000 / ((long)bpm * samplingRate); +} + void stepUp(void const* args) { - if (isRunning) { - step++; - if (step == 16) - { - step = 0; + tick++; + if (tick == noteLen) { + tick = 0; + if (isRunning) { + step++; + if (step == 16) + { + step = 0; + } + UIController.setPlayingStep(step); } - UIController.setPlayingStep(step); } } @@ -41,13 +56,16 @@ UIController.init(); RtosTimer stepTimer(stepUp, osTimerPeriodic, (void *)0); - stepTimer.start(125); + stepTimer.start(samplingRate); + setNoteLen(); while (true) { UIController.update(); isRunning = UIController.getIsRunning(); + bpm = UIController.getBpm(); + setNoteLen(); OscillatorParam osc; UIController.getOscillatorParam(&osc); @@ -58,7 +76,6 @@ EnvelopeParam env; UIController.getEnvelopeParam(&env); - int bpm = UIController.getBpm(); int accentLevel = UIController.getAccentLevel(); #if (UART_TRACE)