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: AverageAnalogIn BaseMachineUIController ExioBufferdController MCP23S17 PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD AT24C1024
main.cpp
- Committer:
- ryood
- Date:
- 2016-11-06
- Revision:
- 2:354ca389e975
- Parent:
- 1:46e088b12083
- Child:
- 3:97e89dad2a44
File content as of revision 2:354ca389e975:
/*
* main.cpp
* BaseMachineUIController Test
*
* mbed Rev 121 / mbed-rtos Rev 117
*
* 2016.11.06 Created
*
*/
#include "mbed.h"
#include "rtos.h"
#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)
{
tick++;
if (tick == noteLen) {
tick = 0;
if (isRunning) {
step++;
if (step == 16)
{
step = 0;
}
UIController.setPlayingStep(step);
}
}
}
int main()
{
#if (UART_TRACE)
printf("*** BaseMachineUIController Test***\r\n");
#endif
UIController.init();
RtosTimer stepTimer(stepUp, osTimerPeriodic, (void *)0);
stepTimer.start(samplingRate);
setNoteLen();
while (true)
{
UIController.update();
isRunning = UIController.getIsRunning();
bpm = UIController.getBpm();
setNoteLen();
OscillatorParam osc;
UIController.getOscillatorParam(&osc);
FilterParam flt;
UIController.getFilterParam(&flt);
EnvelopeParam env;
UIController.getEnvelopeParam(&env);
int accentLevel = UIController.getAccentLevel();
#if (UART_TRACE)
printf("%d %d ", osc.waveShape, osc.pulseWidth);
printf("%d %d ", flt.cutoff, flt.resonance);
printf("%d %d %d %d %d ", env.level, env.length, env.duration, env.decay, env.sustain);
printf("%d %d\r\n", bpm, accentLevel);
#endif
}
}