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 11:20:39 2016 +0000
Revision:
19:241a4b355413
Parent:
18:309f794eba74
Child:
20:00d3b6ace8c7
Add: AverageAnalogIn Library

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