BaseMachine Sequencer UI Test
Dependencies: AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7565LCD
Fork of CH12864F-SPI2_Test by
Diff: main.cpp
- Revision:
- 2:29f0fe703d39
- Parent:
- 1:23bc297e8bfe
- Child:
- 3:6d89fd15e299
diff -r 23bc297e8bfe -r 29f0fe703d39 main.cpp --- a/main.cpp Wed Aug 17 12:08:31 2016 +0000 +++ b/main.cpp Wed Aug 17 12:46:21 2016 +0000 @@ -5,13 +5,16 @@ * 2016.08.17 * */ + +#define UART_TRACE (1) + #include "mbed.h" #include "rtos.h" #include "st7565LCD.h" - -#define UART_TRACE (1) -//#include "Sequence.h" -//#include "ST7565_SequencerDisplay.h" +#include "PinDetect.h" +//#include "RotaryEncoder.h" +#include "Sequence.h" +#include "ST7565_SequencerDisplay.h" #define TITLE_STR1 ("BaseMachine Sequencer") #define TITLE_STR2 ("20160817") @@ -21,6 +24,8 @@ const int BPM_MIN = 60; const int BPM_MAX = 240; +// Devices +// //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0); ST7565 gLCD(PB_15, PB_13, PB_12, PB_2, PB_1); @@ -32,6 +37,42 @@ AnalogIn AinDuration(PA_4); AnalogIn AinDecay(PA_1); AnalogIn AinSustain(PA_0); +/* +RotaryEncoder RotEncStep(D2, D3, 0, SEQUENCE_N - 1, 0); +RotaryEncoder RotEncPitch(D4, D5, 0, PITCH_MAX, 0); +RotaryEncoder RotEncBpm(D14, D15, BPM_MIN, BPM_MAX, 120); +*/ +PinDetect PinWaveShape(PD_2, PullUp); +PinDetect PinModNumber(PC_11, PullUp); +PinDetect PinOctaveUp(PC_10, PullUp); +PinDetect PinOctaveDown(PC_12, PullUp); +PinDetect PinNoteOnOff(PA_13, PullUp); +PinDetect PinTie(PA_14, PullUp); +PinDetect PinAccent(PA_15, PullUp); +PinDetect PinRunStop(PB_7, PullUp); + +// Grobal Variables +// +Sequence sequences[SEQUENCE_N]; +ST7565_SequencerDisplay sequencerDisplay(&gLCD, sequences, SEQUENCE_N); + +int currentStep = 0; +bool isRunning = false; +bool isDirty = false; +int bpm = 120; + +volatile uint8_t pinFlag = 0x00; + +enum { + bWaveShape = 0x01, + bModNumber = 0x02, + bOctaveUp = 0x04, + bOctaveDown = 0x08, + bNoteOnOff = 0x10, + bTie = 0x20, + bAccent = 0x40, + bRunStop = 0x80 +}; // とりあえずの変数(後でClassのメンバ変数に格納) int waveShape = 0; @@ -48,6 +89,49 @@ uint8_t sustain; //------------------------------------------------------------------------ +// PinDetect ISR +//------------------------------------------------------------------------ +void swWaveShapePressed() +{ + pinFlag |= bWaveShape; +} + +void swModNumberPressed() +{ + pinFlag |= bModNumber; +} + +void swOctaveUpPressed() +{ + pinFlag |= bOctaveUp; +} + +void swOctaveDownPressed() +{ + pinFlag |= bOctaveDown; +} + +void swNoteOnOffPressed() +{ + pinFlag |= bNoteOnOff; +} + +void swTiePressed() +{ + pinFlag |= bTie; +} + +void swAccentPressed() +{ + pinFlag |= bAccent; +} + +void swRunStopPressed() +{ + pinFlag |= bRunStop; +} + +//------------------------------------------------------------------------ // Functions //------------------------------------------------------------------------ void pollingPots() @@ -62,13 +146,86 @@ sustain = AinSustain.read_u16() >> 8; } +void pollingPins() +{ + if (pinFlag & bWaveShape) { + #if (UART_TRACE) + printf("PinWaveShape Pushed\r\n"); + #endif + waveShape++; + if (waveShape == WAVESHAPE_N) { + waveShape = 0; + } + pinFlag &= ~bWaveShape; + } + + if (pinFlag & bModNumber) { + #if (UART_TRACE) + printf("PinModNumber Pushed\r\n"); + #endif + modNumber++; + if (modNumber > MOD_NUMBER_MAX) { + modNumber = 0; + } + pinFlag &= ~bModNumber; + } + + if (pinFlag & bOctaveUp) { + #if (UART_TRACE) + printf("PinOctaveUp Pushed\r\n"); + #endif + sequences[currentStep].setOctave(sequences[currentStep].getOctave() + 1); + pinFlag &= ~bOctaveUp; + } + + if (pinFlag & bOctaveDown) { + #if (UART_TRACE) + printf("PinOctaveDown Pushed\r\n"); + #endif + sequences[currentStep].setOctave(sequences[currentStep].getOctave() - 1); + pinFlag &= ~bOctaveDown; + } + + if (pinFlag & bNoteOnOff) { + #if (UART_TRACE) + printf("PinNoteOnOff Pushed\r\n"); + #endif + sequences[currentStep].noteOn = !sequences[currentStep].noteOn; + pinFlag &= ~bNoteOnOff; + } + + if (pinFlag & bTie) { + #if (UART_TRACE) + printf("PinTie Pushed\r\n"); + #endif + sequences[currentStep].tie = !sequences[currentStep].tie; + pinFlag &= ~bTie; + } + + if (pinFlag & bAccent) { + #if (UART_TRACE) + printf("PinAccent Pushed\r\n"); + #endif + sequences[currentStep].accent = !sequences[currentStep].accent; + pinFlag &= ~bAccent; + } + + if (pinFlag & bRunStop) { + #if (UART_TRACE) + printf("PinRunStop Pushed\r\n"); + #endif + isRunning = !isRunning; + pinFlag &= ~bRunStop; + } +} + void dumpToLCD() { char buff[64]; int col = 0; gLCD.clear(); - /* + sprintf(buff, "Run: %d", isRunning); gLCD.drawstring(0, col++, buff); sprintf(buff, "BPM: %d", bpm); @@ -92,7 +249,6 @@ gLCD.drawstring(64, col++, buff); sprintf(buff, "ModN: %d", modNumber); gLCD.drawstring(64, col++, buff); - */ col = 2; sprintf(buff, "PW%3d CO%3d", pulseWidth, cutOff); @@ -107,13 +263,61 @@ gLCD.display(); } +//------------------------------------------------------------------------ +// Main routine +//------------------------------------------------------------------------ int main() { - printf("\r\n*** BaseMachine Sequencer Test ***\r\n"); - gLCD.begin(0x10); + #if (UART_TRACE) + printf("*** BaseMachine Sequencer ***\r\n"); + #endif + + gLCD.begin(0x12); + gLCD.clear(); + gLCD.drawstring(0, 0, TITLE_STR1); + gLCD.drawstring(0, 1, TITLE_STR2); + gLCD.display(); + Thread::wait(1000); + + PinWaveShape.attach_asserted(&swWaveShapePressed); + PinWaveShape.setAssertValue(0); + PinWaveShape.setSampleFrequency(); + + PinModNumber.attach_asserted(&swModNumberPressed); + PinModNumber.setAssertValue(0); + PinModNumber.setSampleFrequency(); + + PinOctaveUp.attach_asserted(&swOctaveUpPressed); + PinOctaveUp.setAssertValue(0); + PinOctaveUp.setSampleFrequency(); + + PinOctaveDown.attach_asserted(&swOctaveDownPressed); + PinOctaveDown.setAssertValue(0); + PinOctaveDown.setSampleFrequency(); - while (true) { + PinNoteOnOff.attach_asserted(&swNoteOnOffPressed); + PinNoteOnOff.setAssertValue(0); + PinNoteOnOff.setSampleFrequency(); + + PinTie.attach_asserted(&swTiePressed); + PinTie.setAssertValue(0); + PinTie.setSampleFrequency(); + + PinAccent.attach_asserted(&swAccentPressed); + PinAccent.setAssertValue(0); + PinAccent.setSampleFrequency(); + + PinRunStop.attach_asserted(&swRunStopPressed); + PinRunStop.setAssertValue(0); + PinRunStop.setSampleFrequency(); + + #if (UART_TRACE) + printf("Setup Devices OK\r\n"); + #endif + + for (;;) { pollingPots(); + pollingPins(); dumpToLCD(); - } + } }