Browse Source

polyphonic

main
Hendrik Langer 4 years ago
parent
commit
c606d3fe67
  1. 1
      platformio.ini
  2. 26
      src/main.cpp

1
platformio.ini

@ -13,6 +13,7 @@ default_envs = megaatmega2560
[common]
lib_deps =
Tone
# AccelStepper
# SpeedyStepper
MIDI Library

26
src/main.cpp

@ -7,6 +7,8 @@
#include <Arduino.h>
#include "pins/pins_TRIGORILLA_14.h"
#include <Tone.h>
#include <MIDI.h>
#include "midi/noteList.h"
#include "midi/pitches.h"
@ -18,9 +20,9 @@
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings);
byte commandByte;
byte noteByte;
byte velocityByte;
Tone freq1;
Tone freq2;
Tone freq3;
int ledState = LOW; // ledState used to set the LED
const long interval = 1000; // interval at which to blink (milliseconds)
@ -38,16 +40,16 @@ void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity)
//noTone();
long freq = sNotePitches[inNumber];
freq *=4;
while (freq > 15000) freq/=2;
while (freq > 12000) freq/=2;
if (inChannel == 9) digitalWrite(LED_PIN, HIGH);
if (inChannel == 9) {
tone(X_STEP_PIN, freq);
freq1.play(freq);
lastMillis[0] = millis();
} else if (inChannel == 7) {
tone(Y_STEP_PIN, freq);
freq2.play(freq);
lastMillis[1] = millis();
} else if (inChannel == 2) {
tone(Z_STEP_PIN, freq);
freq3.play(freq);
lastMillis[2] = millis();
}
}
@ -58,9 +60,9 @@ void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity)
// Serial.print("\tvelocity: ");
// Serial.println(inVelocity);
if (inChannel == 9) digitalWrite(LED_PIN, LOW);
if (inChannel == 9) noTone(X_STEP_PIN);
if (inChannel == 7) noTone(Y_STEP_PIN);
if (inChannel == 2) noTone(Z_STEP_PIN);
if (inChannel == 9) freq1.stop();
if (inChannel == 7) freq2.stop();
if (inChannel == 2) freq3.stop();
}
void setup()
@ -100,6 +102,10 @@ void setup()
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
freq1.begin(X_STEP_PIN);
freq2.begin(Y_STEP_PIN);
freq3.begin(Z_STEP_PIN);
// digitalWrite(X_ENABLE_PIN, LOW);
// tone(X_STEP_PIN, 14000);
// tone(X_STEP_PIN, 4*440);

Loading…
Cancel
Save