Nucleo SPI Sequencer
Dependencies: AverageAnalogIn N5110 Nucleo_rtos_UI_Test PinDetect RotaryEncoder Sequence mbed-rtos mbed FilterController
Fork of Nucleo_rtos_UI_Test by
Diff: main.cpp
- Revision:
- 6:4e089888b809
- Parent:
- 5:e4b68faa6801
- Child:
- 7:8f38e85705ba
--- a/main.cpp Sun Jun 12 07:13:18 2016 +0000 +++ b/main.cpp Sun Jun 12 08:02:19 2016 +0000 @@ -57,9 +57,6 @@ PinDetect(PA_8, PullUp), }; -//DigitalOut Led1(LED1); - - // Grobal Variables struct sSequence { bool noteOn; @@ -69,11 +66,6 @@ bool accent; } sSequence[SEQUENCE_N]; -struct Oscillator { - int waveForm; - int pulseWidth; -} Oscillator; - struct Filter { int cutOff; int resonance; @@ -101,9 +93,10 @@ Lcd.printString(buff, 0, 2); sprintf(buff, "%1d %1d %1d %1d %3d", sSequence[currentNote].noteOn, sSequence[currentNote].tie, sSequence[currentNote].accent, - isRunning, Oscillator.waveForm); + isRunning, sequenceSender.getWaveShape()); Lcd.printString(buff, 0, 3); - sprintf(buff, "%3d %3d %3d", Oscillator.pulseWidth, Filter.envMod, tempo); + sprintf(buff, "%3d %3d %3d", + sequenceSender.getPulseWidth(), Filter.envMod, tempo); Lcd.printString(buff, 0, 4); sprintf(buff, "%3d %3d", Filter.cutOff, Filter.resonance); Lcd.printString(buff, 0, 5); @@ -155,26 +148,22 @@ printf("swRunStopPressed\r\n"); } -void swWaveFormPressed() +void swWaveShapePressed() { - Oscillator.waveForm++; + //Oscillator.waveShape++; + uint8_t shape = sequenceSender.getWaveShape(); + shape++; + if (shape == sequenceSender.WAVESHAPE_N) { + shape = 0; + } + sequenceSender.setWaveShape(shape); isDirty = true; - printf("swWaveFormPressed\r\n"); + printf("swWaveShapePressed\r\n"); } //------------------------------------------------------------------------ // Thread //------------------------------------------------------------------------ -/* -void ledThread(void const *argument) -{ - while (true) { - Led1 = !Led1; - Thread::wait(500); - } -} -*/ - void pollingRotEncs(void const *argument) { while (true) { @@ -199,8 +188,8 @@ while (true) { // pulse width tmp = Pots[0].read_u16() >> 9; // 7bit witdth - if (tmp != Oscillator.pulseWidth) { - Oscillator.pulseWidth = tmp; + if (tmp != (sequenceSender.getPulseWidth() >> 1)) { + sequenceSender.setPulseWidth(tmp << 1); isDirty = true; } // filter envelope moduration @@ -251,7 +240,7 @@ Pins[3].attach_asserted(&swTiePressed); Pins[4].attach_asserted(&swAccentPressed); Pins[5].attach_asserted(&swRunStopPressed); - Pins[6].attach_asserted(&swWaveFormPressed); + Pins[6].attach_asserted(&swWaveShapePressed); for (int i = 0; i < 7; i++) { Pins[i].setAssertValue(0); Pins[i].setSampleFrequency(); @@ -262,13 +251,12 @@ Lcd.setBrightness(0.5); // put LED backlight on 50% // Thread start - //Thread thLed(ledThread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); Thread thRotEnc(pollingRotEncs, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); Thread thPots(pollingPots, NULL, osPriorityNormal, DEFAULT_STACK_SIZE); for (int i = 0; i < SEQUENCE_N; i++) { Sequence& seq = sequenceSender.getSequences()[i]; - seq.setPitch(0); + seq.setPitch(i); seq.setOctave(0); seq.tie = false; }