Nucleo Sequencer of my Base Machine

Dependencies:   Amp AverageAnalogIn Envelope FilterController Sequence BaseMachineComon mbed-rtos mbed

Fork of SpiSequenceSender_Test by Ryo Od

Committer:
ryood
Date:
Tue Aug 23 12:14:34 2016 +0000
Revision:
23:5fe70293e34c
Parent:
22:82f1e7877f9f
Child:
24:040cdcb2ff14
dumpToLCD while stop

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 15:9813d8eaf57e 1 /*
ryood 15:9813d8eaf57e 2 * main.cpp
ryood 15:9813d8eaf57e 3 * SpiSequencerSender_test
ryood 15:9813d8eaf57e 4 *
ryood 15:9813d8eaf57e 5 * 2016.08.20 mbed Rev 121 / mbed-rtos Rev 117で動作確認
ryood 15:9813d8eaf57e 6 *
ryood 15:9813d8eaf57e 7 */
ryood 15:9813d8eaf57e 8
ryood 0:21e39bc75e31 9 #include "mbed.h"
ryood 5:4abac408b827 10 #include "rtos.h"
ryood 16:b0419e3c9079 11 #include "st7565LCD.h"
ryood 18:309f794eba74 12 #include "PinDetect.h"
ryood 20:00d3b6ace8c7 13 #include "RotaryEncoder.h"
ryood 19:241a4b355413 14 #include "AverageAnalogIn.h"
ryood 0:21e39bc75e31 15
ryood 6:fc10eac60b91 16 #define UART_TRACE (0)
ryood 6:fc10eac60b91 17 #include "SpiSequenceSender.h"
ryood 9:3e4e08578e1c 18 #include "EnvelopeGenerator.h"
ryood 9:3e4e08578e1c 19 #include "SpiAmpController.h"
ryood 12:c248781608af 20 #include "SpiFilterController.h"
ryood 17:557658db3e81 21 #include "ST7565_SequencerDisplay.h"
ryood 0:21e39bc75e31 22
ryood 16:b0419e3c9079 23 #define TITLE_STR1 ("BaseMachine Sequencer")
ryood 16:b0419e3c9079 24 #define TITLE_STR2 ("20160823")
ryood 16:b0419e3c9079 25
ryood 6:fc10eac60b91 26 #define SEQUENCE_N (16)
ryood 6:fc10eac60b91 27 #define SPI_RATE (8000000)
ryood 0:21e39bc75e31 28
ryood 14:c173e03ee3ad 29 const int samplingPeriod = 1; // ms
ryood 10:fb04f9959fd9 30 const int bpm = 120;
ryood 10:fb04f9959fd9 31 const int envelopeLength = (60 * 1000 / (bpm * 4)) / samplingPeriod;
ryood 20:00d3b6ace8c7 32 const int waveShape = SpiSequenceSender::WAVESHAPE_SQUARE;
ryood 20:00d3b6ace8c7 33 const int baseNoteNumber = 36;
ryood 20:00d3b6ace8c7 34 const int pitchMax = 12;
ryood 20:00d3b6ace8c7 35 const int bpmMax = 240;
ryood 20:00d3b6ace8c7 36 const int bpmMin = 60;
ryood 14:c173e03ee3ad 37
ryood 14:c173e03ee3ad 38 // Initial Sequence
ryood 14:c173e03ee3ad 39 const int noteOn[SEQUENCE_N] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0 };
ryood 14:c173e03ee3ad 40 const int octave[SEQUENCE_N] = {-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
ryood 14:c173e03ee3ad 41 const int pitch[SEQUENCE_N] = { 9, 7, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 };
ryood 14:c173e03ee3ad 42 const int tie[SEQUENCE_N] = { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 };
ryood 10:fb04f9959fd9 43
ryood 16:b0419e3c9079 44 // Devices
ryood 16:b0419e3c9079 45 //
ryood 16:b0419e3c9079 46 //SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
ryood 19:241a4b355413 47 SPI spiMaster(PA_7, PA_6, PA_5);
ryood 16:b0419e3c9079 48
ryood 16:b0419e3c9079 49 //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
ryood 16:b0419e3c9079 50 ST7565 gLCD(PB_15, PB_13, PB_12, PB_2, PB_1);
ryood 16:b0419e3c9079 51
ryood 19:241a4b355413 52 AverageAnalogIn AinPulseWidth(PC_2);
ryood 19:241a4b355413 53 AverageAnalogIn AinCutOff(PB_0);
ryood 19:241a4b355413 54 AverageAnalogIn AinResonance(PC_1);
ryood 19:241a4b355413 55 AverageAnalogIn AinEnvMod(PC_3);
ryood 19:241a4b355413 56 AverageAnalogIn AinLevel(PC_0);
ryood 19:241a4b355413 57 AverageAnalogIn AinDuration(PA_4);
ryood 19:241a4b355413 58 AverageAnalogIn AinDecay(PA_1);
ryood 19:241a4b355413 59 AverageAnalogIn AinSustain(PA_0);
ryood 10:fb04f9959fd9 60
ryood 20:00d3b6ace8c7 61 RotaryEncoder RotEncStep(D2, D3, 0, SEQUENCE_N - 1, 0);
ryood 20:00d3b6ace8c7 62 RotaryEncoder RotEncPitch(D4, D5, 0, pitchMax, 0);
ryood 20:00d3b6ace8c7 63 RotaryEncoder RotEncBpm(D14, D15, bpmMin, bpmMax, 120);
ryood 20:00d3b6ace8c7 64
ryood 18:309f794eba74 65 PinDetect PinWaveShape(PD_2, PullUp);
ryood 18:309f794eba74 66 PinDetect PinModNumber(PC_11, PullUp);
ryood 18:309f794eba74 67 PinDetect PinOctaveUp(PC_10, PullUp);
ryood 18:309f794eba74 68 PinDetect PinOctaveDown(PC_12, PullUp);
ryood 18:309f794eba74 69 PinDetect PinNoteOnOff(PA_13, PullUp);
ryood 18:309f794eba74 70 PinDetect PinTie(PA_14, PullUp);
ryood 18:309f794eba74 71 PinDetect PinAccent(PA_15, PullUp);
ryood 18:309f794eba74 72 PinDetect PinRunStop(PB_7, PullUp);
ryood 18:309f794eba74 73
ryood 16:b0419e3c9079 74 // Grobal Variables
ryood 16:b0419e3c9079 75 //
ryood 16:b0419e3c9079 76 Sequence sequences[SEQUENCE_N];
ryood 16:b0419e3c9079 77 SpiSequenceSender sequenceSender(&spiMaster, D9, sequences, SEQUENCE_N, samplingPeriod, bpm);
ryood 6:fc10eac60b91 78
ryood 10:fb04f9959fd9 79 Envelope envelope(4095, envelopeLength, envelopeLength*3/4, envelopeLength/2, 2047);
ryood 9:3e4e08578e1c 80 EnvelopeGenerator envelopeGenerator;
ryood 9:3e4e08578e1c 81 SpiAmpController ampController(&spiMaster, D8, D7);
ryood 6:fc10eac60b91 82
ryood 12:c248781608af 83 SpiFilterController filterController(&spiMaster, D10);
ryood 0:21e39bc75e31 84
ryood 17:557658db3e81 85 ST7565_SequencerDisplay sequencerDisplay(&gLCD, sequences, SEQUENCE_N);
ryood 17:557658db3e81 86
ryood 16:b0419e3c9079 87 volatile int currentStep = 0;
ryood 16:b0419e3c9079 88 volatile bool isRunning = false;
ryood 16:b0419e3c9079 89 volatile bool isDirty = false;
ryood 16:b0419e3c9079 90 volatile uint8_t pinFlag = 0x00;
ryood 16:b0419e3c9079 91
ryood 16:b0419e3c9079 92 enum PinBit {
ryood 16:b0419e3c9079 93 bWaveShape = 0x01,
ryood 16:b0419e3c9079 94 bModNumber = 0x02,
ryood 16:b0419e3c9079 95 bOctaveUp = 0x04,
ryood 16:b0419e3c9079 96 bOctaveDown = 0x08,
ryood 16:b0419e3c9079 97 bNoteOnOff = 0x10,
ryood 16:b0419e3c9079 98 bTie = 0x20,
ryood 16:b0419e3c9079 99 bAccent = 0x40,
ryood 16:b0419e3c9079 100 bRunStop = 0x80
ryood 16:b0419e3c9079 101 };
ryood 16:b0419e3c9079 102
ryood 16:b0419e3c9079 103 // とりあえずの変数(後でClassのメンバ変数に格納)
ryood 16:b0419e3c9079 104 #define MOD_NUMBER_MAX 1
ryood 16:b0419e3c9079 105 volatile int modNumber = 0;
ryood 21:c4d09aaa52b9 106 volatile uint8_t envMod = 127;
ryood 16:b0419e3c9079 107
ryood 16:b0419e3c9079 108 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 109 // Callback functions
ryood 16:b0419e3c9079 110 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 111 void updateFunction(int ticks)
ryood 8:de409197ff95 112 {
ryood 8:de409197ff95 113 if (ticks == 0) {
ryood 9:3e4e08578e1c 114 envelopeGenerator.init(envelope);
ryood 8:de409197ff95 115 }
ryood 14:c173e03ee3ad 116
ryood 15:9813d8eaf57e 117 if (sequenceSender.getSequences()[sequenceSender.getStep()].isNoteOn()) {
ryood 14:c173e03ee3ad 118 uint16_t level = envelopeGenerator.getModLevel();
ryood 14:c173e03ee3ad 119 ampController.outDca(level);
ryood 14:c173e03ee3ad 120 } else {
ryood 14:c173e03ee3ad 121 ampController.outDca(0);
ryood 14:c173e03ee3ad 122 }
ryood 9:3e4e08578e1c 123 envelopeGenerator.update();
ryood 12:c248781608af 124
ryood 15:9813d8eaf57e 125 filterController.outDcf();
ryood 17:557658db3e81 126
ryood 17:557658db3e81 127 // ToDo: 再生中のLCD表示を検討→SPI1とSPI2の信号のタイミングを調査
ryood 17:557658db3e81 128 //sequencerDisplay.update(SequencerDisplay::stop, sequenceSender.getStep());
ryood 8:de409197ff95 129 }
ryood 8:de409197ff95 130
ryood 16:b0419e3c9079 131 //------------------------------------------------------------------------
ryood 18:309f794eba74 132 // PinDetect ISR
ryood 18:309f794eba74 133 //------------------------------------------------------------------------
ryood 18:309f794eba74 134 void swWaveShapePressed()
ryood 18:309f794eba74 135 {
ryood 18:309f794eba74 136 pinFlag |= bWaveShape;
ryood 18:309f794eba74 137 }
ryood 18:309f794eba74 138
ryood 18:309f794eba74 139 void swModNumberPressed()
ryood 18:309f794eba74 140 {
ryood 18:309f794eba74 141 pinFlag |= bModNumber;
ryood 18:309f794eba74 142 }
ryood 18:309f794eba74 143
ryood 18:309f794eba74 144 void swOctaveUpPressed()
ryood 18:309f794eba74 145 {
ryood 18:309f794eba74 146 pinFlag |= bOctaveUp;
ryood 18:309f794eba74 147 }
ryood 18:309f794eba74 148
ryood 18:309f794eba74 149 void swOctaveDownPressed()
ryood 18:309f794eba74 150 {
ryood 18:309f794eba74 151 pinFlag |= bOctaveDown;
ryood 18:309f794eba74 152 }
ryood 18:309f794eba74 153
ryood 18:309f794eba74 154 void swNoteOnOffPressed()
ryood 18:309f794eba74 155 {
ryood 18:309f794eba74 156 pinFlag |= bNoteOnOff;
ryood 18:309f794eba74 157 }
ryood 18:309f794eba74 158
ryood 18:309f794eba74 159 void swTiePressed()
ryood 18:309f794eba74 160 {
ryood 18:309f794eba74 161 pinFlag |= bTie;
ryood 18:309f794eba74 162 }
ryood 18:309f794eba74 163
ryood 18:309f794eba74 164 void swAccentPressed()
ryood 18:309f794eba74 165 {
ryood 18:309f794eba74 166 pinFlag |= bAccent;
ryood 18:309f794eba74 167 }
ryood 18:309f794eba74 168
ryood 18:309f794eba74 169 void swRunStopPressed()
ryood 18:309f794eba74 170 {
ryood 18:309f794eba74 171 pinFlag |= bRunStop;
ryood 18:309f794eba74 172 }
ryood 18:309f794eba74 173
ryood 18:309f794eba74 174 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 175 // Functions
ryood 16:b0419e3c9079 176 //------------------------------------------------------------------------
ryood 19:241a4b355413 177 void pollingPots()
ryood 19:241a4b355413 178 {
ryood 20:00d3b6ace8c7 179 //pulseWidth = AinPulseWidth.read_u16() >> 8;
ryood 20:00d3b6ace8c7 180
ryood 19:241a4b355413 181 filterController.setCutoff(AinCutOff.read_u16() >> 8);
ryood 19:241a4b355413 182 filterController.setResonance(AinResonance.read_u16() >> 8);
ryood 20:00d3b6ace8c7 183 //envMod = AinEnvMod.read_u16() >> 8;
ryood 19:241a4b355413 184
ryood 19:241a4b355413 185 //envelope.setLevel(AinLevel.read_u16() >> 4);
ryood 19:241a4b355413 186 envelope.setLevel(4095);
ryood 19:241a4b355413 187 envelope.setDuration(AinDuration.read() * envelopeLength);
ryood 19:241a4b355413 188 envelope.setDecay(AinDecay.read() * envelopeLength);
ryood 19:241a4b355413 189 envelope.setSustain(AinSustain.read() * 4095);
ryood 20:00d3b6ace8c7 190 }
ryood 20:00d3b6ace8c7 191
ryood 20:00d3b6ace8c7 192 void pollingRotEncs()
ryood 20:00d3b6ace8c7 193 {
ryood 20:00d3b6ace8c7 194 int _bpm = RotEncBpm.getVal();
ryood 20:00d3b6ace8c7 195 if (_bpm != sequenceSender.getBpm()) {
ryood 20:00d3b6ace8c7 196 sequenceSender.setBpm(_bpm);
ryood 20:00d3b6ace8c7 197 isDirty = true;
ryood 20:00d3b6ace8c7 198 }
ryood 20:00d3b6ace8c7 199
ryood 20:00d3b6ace8c7 200 int _step = RotEncStep.getVal();
ryood 20:00d3b6ace8c7 201 if (_step != currentStep) {
ryood 20:00d3b6ace8c7 202 currentStep = _step;
ryood 20:00d3b6ace8c7 203 // syncronize sequence value & Rotary Encoder's value
ryood 20:00d3b6ace8c7 204 RotEncPitch.setVal(sequences[currentStep].getPitch());
ryood 20:00d3b6ace8c7 205 isDirty = true;
ryood 20:00d3b6ace8c7 206 }
ryood 20:00d3b6ace8c7 207
ryood 20:00d3b6ace8c7 208 int _pitch = RotEncPitch.getVal();
ryood 20:00d3b6ace8c7 209 if (_pitch != sequences[currentStep].getPitch()) {
ryood 20:00d3b6ace8c7 210 sequences[currentStep].setPitch(_pitch);
ryood 20:00d3b6ace8c7 211 isDirty = true;
ryood 20:00d3b6ace8c7 212 }
ryood 19:241a4b355413 213 }
ryood 19:241a4b355413 214
ryood 18:309f794eba74 215 void pollingPins()
ryood 18:309f794eba74 216 {
ryood 18:309f794eba74 217 if (pinFlag & bWaveShape) {
ryood 18:309f794eba74 218 #if (UART_TRACE)
ryood 18:309f794eba74 219 printf("PinWaveShape Pushed\r\n");
ryood 18:309f794eba74 220 #endif
ryood 18:309f794eba74 221 uint8_t waveShape = sequenceSender.getWaveShape();
ryood 18:309f794eba74 222 waveShape++;
ryood 18:309f794eba74 223 if (waveShape < SpiSequenceSender::WAVESHAPE_N) {
ryood 18:309f794eba74 224 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 225 } else {
ryood 18:309f794eba74 226 sequenceSender.setWaveShape(0);
ryood 18:309f794eba74 227 }
ryood 18:309f794eba74 228 pinFlag &= ~bWaveShape;
ryood 18:309f794eba74 229 }
ryood 18:309f794eba74 230
ryood 18:309f794eba74 231 if (pinFlag & bModNumber) {
ryood 18:309f794eba74 232 #if (UART_TRACE)
ryood 18:309f794eba74 233 printf("PinModNumber Pushed\r\n");
ryood 18:309f794eba74 234 #endif
ryood 18:309f794eba74 235 modNumber++;
ryood 18:309f794eba74 236 if (modNumber > MOD_NUMBER_MAX) {
ryood 18:309f794eba74 237 modNumber = 0;
ryood 18:309f794eba74 238 }
ryood 18:309f794eba74 239 pinFlag &= ~bModNumber;
ryood 18:309f794eba74 240 }
ryood 18:309f794eba74 241
ryood 18:309f794eba74 242 if (pinFlag & bOctaveUp) {
ryood 18:309f794eba74 243 #if (UART_TRACE)
ryood 18:309f794eba74 244 printf("PinOctaveUp Pushed\r\n");
ryood 18:309f794eba74 245 #endif
ryood 18:309f794eba74 246 sequences[currentStep].setOctave(sequences[currentStep].getOctave() + 1);
ryood 18:309f794eba74 247 pinFlag &= ~bOctaveUp;
ryood 18:309f794eba74 248 }
ryood 18:309f794eba74 249
ryood 18:309f794eba74 250 if (pinFlag & bOctaveDown) {
ryood 18:309f794eba74 251 #if (UART_TRACE)
ryood 18:309f794eba74 252 printf("PinOctaveDown Pushed\r\n");
ryood 18:309f794eba74 253 #endif
ryood 18:309f794eba74 254 sequences[currentStep].setOctave(sequences[currentStep].getOctave() - 1);
ryood 18:309f794eba74 255 pinFlag &= ~bOctaveDown;
ryood 18:309f794eba74 256 }
ryood 18:309f794eba74 257
ryood 18:309f794eba74 258 if (pinFlag & bNoteOnOff) {
ryood 18:309f794eba74 259 #if (UART_TRACE)
ryood 18:309f794eba74 260 printf("PinNoteOnOff Pushed\r\n");
ryood 18:309f794eba74 261 #endif
ryood 18:309f794eba74 262 sequences[currentStep].setNoteOn(!sequences[currentStep].isNoteOn());
ryood 18:309f794eba74 263 pinFlag &= ~bNoteOnOff;
ryood 18:309f794eba74 264 }
ryood 18:309f794eba74 265
ryood 18:309f794eba74 266 if (pinFlag & bTie) {
ryood 18:309f794eba74 267 #if (UART_TRACE)
ryood 18:309f794eba74 268 printf("PinTie Pushed\r\n");
ryood 18:309f794eba74 269 #endif
ryood 18:309f794eba74 270 sequences[currentStep].setTie(!sequences[currentStep].isTie());
ryood 18:309f794eba74 271 pinFlag &= ~bTie;
ryood 18:309f794eba74 272 }
ryood 18:309f794eba74 273
ryood 18:309f794eba74 274 if (pinFlag & bAccent) {
ryood 18:309f794eba74 275 #if (UART_TRACE)
ryood 18:309f794eba74 276 printf("PinAccent Pushed\r\n");
ryood 18:309f794eba74 277 #endif
ryood 18:309f794eba74 278 sequences[currentStep].setAccent(!sequences[currentStep].isAccent());
ryood 18:309f794eba74 279 pinFlag &= ~bAccent;
ryood 18:309f794eba74 280 }
ryood 18:309f794eba74 281
ryood 18:309f794eba74 282 if (pinFlag & bRunStop) {
ryood 18:309f794eba74 283 #if (UART_TRACE)
ryood 18:309f794eba74 284 printf("PinRunStop Pushed\r\n");
ryood 18:309f794eba74 285 #endif
ryood 18:309f794eba74 286 if (isRunning) {
ryood 22:82f1e7877f9f 287 ampController.outDca(0);
ryood 18:309f794eba74 288 sequenceSender.stop();
ryood 18:309f794eba74 289 isRunning = false;
ryood 18:309f794eba74 290 } else {
ryood 18:309f794eba74 291 sequenceSender.run(currentStep);
ryood 18:309f794eba74 292 isRunning = true;
ryood 18:309f794eba74 293 }
ryood 18:309f794eba74 294 pinFlag &= ~bRunStop;
ryood 18:309f794eba74 295 }
ryood 18:309f794eba74 296 }
ryood 18:309f794eba74 297
ryood 16:b0419e3c9079 298 void dumpToLCD()
ryood 16:b0419e3c9079 299 {
ryood 16:b0419e3c9079 300 char buff[64];
ryood 16:b0419e3c9079 301 int col = 0;
ryood 16:b0419e3c9079 302
ryood 16:b0419e3c9079 303 gLCD.clear();
ryood 16:b0419e3c9079 304
ryood 16:b0419e3c9079 305 sprintf(buff, "Run: %d", isRunning);
ryood 16:b0419e3c9079 306 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 307 sprintf(buff, "BPM: %d", sequenceSender.getBpm());
ryood 16:b0419e3c9079 308 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 309
ryood 16:b0419e3c9079 310 sprintf(buff, "Step: %d", currentStep);
ryood 16:b0419e3c9079 311 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 312 sprintf(buff, "NoteOn: %d", sequences[currentStep].isNoteOn());
ryood 16:b0419e3c9079 313 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 314 sprintf(buff, "Pitch: %d", sequences[currentStep].getPitch());
ryood 16:b0419e3c9079 315 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 316 sprintf(buff, "Octave: %d", sequences[currentStep].getOctave());
ryood 16:b0419e3c9079 317 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 318 sprintf(buff, "Tie: %d", sequences[currentStep].isTie());
ryood 16:b0419e3c9079 319 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 320 sprintf(buff, "Accent: %d", sequences[currentStep].isAccent());
ryood 16:b0419e3c9079 321 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 322
ryood 16:b0419e3c9079 323 col = 0;
ryood 16:b0419e3c9079 324 sprintf(buff, "WavS: %d", sequenceSender.getWaveShape());
ryood 16:b0419e3c9079 325 gLCD.drawstring(64, col++, buff);
ryood 16:b0419e3c9079 326 sprintf(buff, "ModN: %d", modNumber);
ryood 16:b0419e3c9079 327 gLCD.drawstring(64, col++, buff);
ryood 16:b0419e3c9079 328
ryood 16:b0419e3c9079 329 col = 2;
ryood 19:241a4b355413 330 sprintf(buff, "PW%3d CO%3d", sequenceSender.getPulseWidth(), filterController.getCutoff());
ryood 16:b0419e3c9079 331 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 332 sprintf(buff, "RS%3d EV%3d", filterController.getResonance(), envMod);
ryood 16:b0419e3c9079 333 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 334 sprintf(buff, "LV%3d DR%3d", envelope.getLevel(), envelope.getDuration());
ryood 16:b0419e3c9079 335 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 336 sprintf(buff, "DC%3d ST%3d", envelope.getDecay(), envelope.getSustain());
ryood 16:b0419e3c9079 337 gLCD.drawstring(60, col++, buff);
ryood 16:b0419e3c9079 338
ryood 16:b0419e3c9079 339 gLCD.display();
ryood 16:b0419e3c9079 340 }
ryood 16:b0419e3c9079 341
ryood 16:b0419e3c9079 342 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 343 // Main routine
ryood 16:b0419e3c9079 344 //------------------------------------------------------------------------
ryood 0:21e39bc75e31 345 int main()
ryood 0:21e39bc75e31 346 {
ryood 18:309f794eba74 347 #if (UART_TRACE)
ryood 18:309f794eba74 348 printf("*** BaseMachine Sequencer ***\r\n");
ryood 18:309f794eba74 349 #endif
ryood 18:309f794eba74 350
ryood 16:b0419e3c9079 351 // Setup Devices
ryood 16:b0419e3c9079 352 //
ryood 0:21e39bc75e31 353 spiMaster.format(8, 0);
ryood 0:21e39bc75e31 354 spiMaster.frequency(SPI_RATE);
ryood 0:21e39bc75e31 355
ryood 16:b0419e3c9079 356 gLCD.begin(0x12);
ryood 16:b0419e3c9079 357 gLCD.clear();
ryood 16:b0419e3c9079 358 gLCD.drawstring(0, 0, TITLE_STR1);
ryood 16:b0419e3c9079 359 gLCD.drawstring(0, 1, TITLE_STR2);
ryood 16:b0419e3c9079 360 gLCD.display();
ryood 16:b0419e3c9079 361 Thread::wait(1000);
ryood 16:b0419e3c9079 362
ryood 17:557658db3e81 363 dumpToLCD();
ryood 17:557658db3e81 364 Thread::wait(1000);
ryood 17:557658db3e81 365
ryood 20:00d3b6ace8c7 366 RotEncStep.setInterval(100);
ryood 20:00d3b6ace8c7 367 RotEncPitch.setInterval(100);
ryood 20:00d3b6ace8c7 368 RotEncBpm.setInterval(100);
ryood 17:557658db3e81 369
ryood 18:309f794eba74 370 PinWaveShape.attach_asserted(&swWaveShapePressed);
ryood 18:309f794eba74 371 PinWaveShape.setAssertValue(0);
ryood 18:309f794eba74 372 PinWaveShape.setSampleFrequency();
ryood 18:309f794eba74 373
ryood 18:309f794eba74 374 PinModNumber.attach_asserted(&swModNumberPressed);
ryood 18:309f794eba74 375 PinModNumber.setAssertValue(0);
ryood 18:309f794eba74 376 PinModNumber.setSampleFrequency();
ryood 18:309f794eba74 377
ryood 18:309f794eba74 378 PinOctaveUp.attach_asserted(&swOctaveUpPressed);
ryood 18:309f794eba74 379 PinOctaveUp.setAssertValue(0);
ryood 18:309f794eba74 380 PinOctaveUp.setSampleFrequency();
ryood 18:309f794eba74 381
ryood 18:309f794eba74 382 PinOctaveDown.attach_asserted(&swOctaveDownPressed);
ryood 18:309f794eba74 383 PinOctaveDown.setAssertValue(0);
ryood 18:309f794eba74 384 PinOctaveDown.setSampleFrequency();
ryood 18:309f794eba74 385
ryood 18:309f794eba74 386 PinNoteOnOff.attach_asserted(&swNoteOnOffPressed);
ryood 18:309f794eba74 387 PinNoteOnOff.setAssertValue(0);
ryood 18:309f794eba74 388 PinNoteOnOff.setSampleFrequency();
ryood 18:309f794eba74 389
ryood 18:309f794eba74 390 PinTie.attach_asserted(&swTiePressed);
ryood 18:309f794eba74 391 PinTie.setAssertValue(0);
ryood 18:309f794eba74 392 PinTie.setSampleFrequency();
ryood 18:309f794eba74 393
ryood 18:309f794eba74 394 PinAccent.attach_asserted(&swAccentPressed);
ryood 18:309f794eba74 395 PinAccent.setAssertValue(0);
ryood 18:309f794eba74 396 PinAccent.setSampleFrequency();
ryood 18:309f794eba74 397
ryood 18:309f794eba74 398 PinRunStop.attach_asserted(&swRunStopPressed);
ryood 18:309f794eba74 399 PinRunStop.setAssertValue(0);
ryood 18:309f794eba74 400 PinRunStop.setSampleFrequency();
ryood 18:309f794eba74 401
ryood 22:82f1e7877f9f 402 // Initialize objects
ryood 0:21e39bc75e31 403 //
ryood 15:9813d8eaf57e 404 Sequence::setBaseNoteNumber(baseNoteNumber);
ryood 14:c173e03ee3ad 405
ryood 19:241a4b355413 406 // Initialize sequences
ryood 0:21e39bc75e31 407 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 0:21e39bc75e31 408 Sequence& seq = sequenceSender.getSequences()[i];
ryood 14:c173e03ee3ad 409 seq.setPitch(pitch[i]);
ryood 14:c173e03ee3ad 410 seq.setOctave(octave[i]);
ryood 15:9813d8eaf57e 411 seq.setNoteOn(noteOn[i]);
ryood 15:9813d8eaf57e 412 seq.setTie(tie[i]);
ryood 0:21e39bc75e31 413 }
ryood 6:fc10eac60b91 414
ryood 9:3e4e08578e1c 415 envelopeGenerator.init(envelope);
ryood 12:c248781608af 416
ryood 16:b0419e3c9079 417 sequenceSender.attachUpdate(&updateFunction);
ryood 14:c173e03ee3ad 418 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 419 //sequenceSender.run(0);
ryood 5:4abac408b827 420
ryood 5:4abac408b827 421 for (;;) {
ryood 20:00d3b6ace8c7 422 pollingPots();
ryood 20:00d3b6ace8c7 423 pollingRotEncs();
ryood 18:309f794eba74 424 pollingPins();
ryood 23:5fe70293e34c 425 if (!isRunning) {
ryood 23:5fe70293e34c 426 dumpToLCD();
ryood 23:5fe70293e34c 427 }
ryood 5:4abac408b827 428 }
ryood 0:21e39bc75e31 429 }