BaseMachine Sequencer UI Test
Dependencies: AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7565LCD
Fork of CH12864F-SPI2_Test by
Diff: main.cpp
- Revision:
- 3:6d89fd15e299
- Parent:
- 2:29f0fe703d39
- Child:
- 4:899dfeba84de
--- a/main.cpp Wed Aug 17 12:46:21 2016 +0000 +++ b/main.cpp Wed Aug 17 13:08:48 2016 +0000 @@ -12,7 +12,7 @@ #include "rtos.h" #include "st7565LCD.h" #include "PinDetect.h" -//#include "RotaryEncoder.h" +#include "RotaryEncoder.h" #include "Sequence.h" #include "ST7565_SequencerDisplay.h" @@ -37,11 +37,11 @@ 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); @@ -56,11 +56,10 @@ Sequence sequences[SEQUENCE_N]; ST7565_SequencerDisplay sequencerDisplay(&gLCD, sequences, SEQUENCE_N); -int currentStep = 0; -bool isRunning = false; -bool isDirty = false; -int bpm = 120; - +volatile int currentStep = 0; +volatile bool isRunning = false; +volatile bool isDirty = false; +volatile int bpm = 120; volatile uint8_t pinFlag = 0x00; enum { @@ -75,18 +74,18 @@ }; // とりあえずの変数(後でClassのメンバ変数に格納) -int waveShape = 0; -int modNumber = 0; #define WAVESHAPE_N 2 #define MOD_NUMBER_MAX 1 -uint8_t pulseWidth; -uint8_t cutOff; -uint8_t resonance; -uint8_t envMod; -uint8_t level; -uint8_t duration; -uint8_t decay; -uint8_t sustain; +volatile int waveShape = 0; +volatile int modNumber = 0; +volatile uint8_t pulseWidth; +volatile uint8_t cutOff; +volatile uint8_t resonance; +volatile uint8_t envMod; +volatile uint8_t level; +volatile uint8_t duration; +volatile uint8_t decay; +volatile uint8_t sustain; //------------------------------------------------------------------------ // PinDetect ISR @@ -146,6 +145,29 @@ sustain = AinSustain.read_u16() >> 8; } +void pollingRotEncs() +{ + int _bpm = RotEncBpm.getVal(); + if (_bpm != bpm) { + bpm = _bpm; + isDirty = true; + } + + int _step = RotEncStep.getVal(); + if (_step != currentStep) { + currentStep = _step; + // syncronize sequence value & Rotary Encoder's value + RotEncPitch.setVal(sequences[currentStep].getPitch()); + isDirty = true; + } + + int _pitch = RotEncPitch.getVal(); + if (_pitch != sequences[currentStep].getPitch()) { + sequences[currentStep].setPitch(_pitch); + isDirty = true; + } +} + void pollingPins() { if (pinFlag & bWaveShape) { @@ -279,6 +301,10 @@ gLCD.display(); Thread::wait(1000); + RotEncStep.setInterval(100); + RotEncPitch.setInterval(100); + RotEncBpm.setInterval(100); + PinWaveShape.attach_asserted(&swWaveShapePressed); PinWaveShape.setAssertValue(0); PinWaveShape.setSampleFrequency(); @@ -318,6 +344,7 @@ for (;;) { pollingPots(); pollingPins(); + pollingRotEncs(); dumpToLCD(); } }