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-09
- Revision:
- 4:f79bf2806617
- Parent:
- 3:97e89dad2a44
- Child:
- 5:7f49c9ca7c04
File content as of revision 4:f79bf2806617:
/*
* main.cpp
* BaseMachineUIController Test
*
* mbed Rev 121 / mbed-rtos Rev 117
*
* 2016.11.06 Created
*
*/
#include "mbed.h"
#include "rtos.h"
#define UART_TRACE (1)
#include "BaseMachineUIController.h"
#include "ExioInBuffer.h"
#include "ExioBufferedDebounceIn.h"
#include "Sequence.h"
const int samplingRate = 1;
BaseMachineUIController UIController;
SPI Spi(PC_12, PC_11, PC_10); // SPI3: mosi, miso, sclk
// MExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset);
ExioMcp23s17 Exio(0x00, Spi, PD_2, PA_13);
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();
// Reset MCP23S17 (初期化時にreset()が必要)
Exio.reset();
ExioInBuffer exioInBufferA(&Exio, ExioPortA);
ExioInBuffer exioInBufferB(&Exio, ExioPortB);
ExioBufferedDebounceIn inB[] = {
ExioBufferedDebounceIn(&exioInBufferB, 0),
ExioBufferedDebounceIn(&exioInBufferB, 1),
ExioBufferedDebounceIn(&exioInBufferB, 2),
ExioBufferedDebounceIn(&exioInBufferB, 3),
ExioBufferedDebounceIn(&exioInBufferB, 4),
ExioBufferedDebounceIn(&exioInBufferB, 5),
ExioBufferedDebounceIn(&exioInBufferB, 6),
ExioBufferedDebounceIn(&exioInBufferB, 7)
};
exioInBufferA.run(10);
exioInBufferB.run(10);
for (int i = 0; i < 8; i++) {
inB[i].set_debounce_us(10000);
}
RtosTimer stepTimer(stepUp, osTimerPeriodic, (void *)0);
stepTimer.start(samplingRate);
setNoteLen();
while (true)
{
UIController.update();
isRunning = UIController.getIsRunning();
bpm = UIController.getBpm();
setNoteLen();
Sequence sequences[SEQUENCE_N];
UIController.getSequences(&sequences);
OscillatorParam osc;
UIController.getOscillatorParam(&osc);
FilterParam flt;
UIController.getFilterParam(&flt);
EnvelopeParam env;
UIController.getEnvelopeParam(&env);
int accentLevel = UIController.getAccentLevel();
uint8_t va = exioInBufferA.readPort();
#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);
for (int i = 0; i < SEQUENCE_N; i++) {
printf("%d %d %d %d %d %u\r\n",
i,
sequences[i].isNoteOn(),
sequences[i].getPitch(),
sequences[i].isTie(),
sequences[i].isAccent(),
(sequences[i].getFrequency10()) >> 16
);
}
printf("Exio PortA: %d\r\n", va);
for (int i = 0; i < 8; i++) {
int vb = inB[i].read();
printf("%d ", vb);
}
printf("\r\n");
#endif
}
}