I am trying playing waveforms sounds on Teensy4.1 from Teensy LC using Midi communication.
i will connect ( Teensy LC's Gnd to Teensy 4.1's Gnd) & ( Teensy LC's Tx to Teensy 4.1's Rx). to send Midi commands Teensy LC to Teensy4.1.
I upload below code succesfully to Teensy
when I try this code to Teensy4.1:
I got error
how to fix it????
i will connect ( Teensy LC's Gnd to Teensy 4.1's Gnd) & ( Teensy LC's Tx to Teensy 4.1's Rx). to send Midi commands Teensy LC to Teensy4.1.
I upload below code succesfully to Teensy
Code:
#include <Keypad.h>
#include <MIDI.h>
const uint8_t ROWS = 8; // 8 rows For TEENSY LC as MIDI Keypoard
const uint8_t COLS = 8; //8 columns
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8},
{9,10,11,12,13,14,15,16},
{17,18,19,20,21,22,23,24},
{25,26,27,28,29,30,31,32},
{33,34,35,36,37,38,39,40}, // 8 x 8
{41,42,43,44,45,46,47,48},
{49,50,51,52,53,54,55,56},
{57,58,59,60,61,62,63,64},
};
uint8_t rowPins[ROWS] = { 4,5,6,7,8,9,14,15 }; // 4,5,6,7,8,9,14,15 16,17,18,19,20,21,22,23
uint8_t colPins[COLS] = {16,17,18,19,20,21,22,23 };
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int channel = 1;
void setup() {
MIDI.begin();
kpd.setHoldTime(2000);
}
void loop() {
if (kpd.getKeys()) {
for (int i = 0; i < LIST_MAX; i++)
{ int mykey = (kpd.key[i].kchar);
if (kpd.key[i].stateChanged) // -----------------------------------------Key Changed----------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
MIDI.sendNoteOn(40+mykey, 127, 1);
break;
case RELEASED:
MIDI.sendNoteOff(40+mykey, 0, 1);
break;
}
} //--------------------------------------------------------------------------------------------------
if ((kpd.key[i].stateChanged) && (mykey ==37)) // -----------------------------------------Key Changed----------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
MIDI.sendProgramChange(5, 1);
break;
}
} //--------------------------------------------------------------------------------------------------
}
}
} // -------------------------LOOP -------------------------------------------
when I try this code to Teensy4.1:
Code:
#include <Keypad.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
#include "PlaySynthMusic.h"
#include <MIDI.h>
const uint8_t ROWS = 7; // 7 rows
const uint8_t COLS = 4; //4 columns // Analog pin_22 , Enc (2,3) ,
char keys[ROWS][COLS] = {
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 14, 15, 16 },
{ 17, 18, 19, 20 },
{ 21, 22, 23, 24 },
{ 25, 26, 27, 28 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 };
uint8_t colPins[COLS] = { 40, 41, 14, 16 };
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=175.7142857142857,257.1428571428571
AudioSynthWaveform waveform2;
AudioSynthWaveform waveform3;
AudioSynthWaveform waveform4;
AudioPlaySdResmp playSdWav1; //xy=185.00003814697266,190.0000171661377
AudioEffectEnvelope envelope1; //xy=324.2857131958008,255.7142848968506
AudioMixer4 mixer1; //xy=754.2857494354248,214.28570938110352
AudioAmplifier amp1; //xy=949.9999656677246,191.42856407165527
AudioAmplifier amp2; //xy=952.8571510314941,242.8571376800537
AudioOutputI2S i2s1; //xy=1099.9999542236328,228.5714282989502
AudioConnection patchCord1(waveform1, envelope1);
AudioConnection patchCord2(waveform3, 0, mixer1, 0);
AudioConnection patchCord3(playSdWav1, 1, mixer1, 1);
AudioConnection patchCord4(envelope1, 0, mixer1, 2);
AudioConnection patchCord9(waveform2, 0, mixer1, 3);
AudioConnection patchCord5(mixer1, amp1);
AudioConnection patchCord6(mixer1, amp2);
AudioConnection patchCord7(amp1, 0, i2s1, 0);
AudioConnection patchCord8(amp2, 0, i2s1, 1);
AudioControlSGTL5000 audioShield; //xy=654.2857131958008,335.71429920196533
// GUItool: end automatically generated code
int RAGA[] = {50,52,54,55,57,59,61,62,64,66,67,69,71,73, 74,76,78};
int pitch[] = {100,277,311,329,370,415,440,493,554,622,659,740,830,880};
char *wav[] = {"WAV1", "WAV2", "WAV3","WAV4", "WAV5", "WAV6"};
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(57600);
kpd.setHoldTime(2000);
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) { Serial.println("Unable to access the SD card"); delay(500); } }
AudioMemory(128);
audioShield.enable();
audioShield.volume(1.0);
amp1.gain(1.0);
amp2.gain(1.0);
playSdWav1.enableInterpolation(true);
waveform1.begin(WAVEFORM_TRIANGLE);
waveform2.begin(WAVEFORM_SQUARE);
waveform3.begin(WAVEFORM_SINE);
Serial.println(" Synth ");
}
unsigned long t=0;
void loop() {
if (kpd.getKeys()) {
for (int i = 0; i < LIST_MAX; i++)
{ int mykey = (kpd.key[i].kchar);
if ((kpd.key[i].stateChanged) && (mykey<29) && (mykey>0)) // -----------------------------------------Key Changed----------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
break;
case RELEASED:
break;
}
} //--------------------------------------------------------------------------------------------------
} }
// --------------------------------Read midi--------------------------------------------------------------
int type, note, velocity, channel, d1, d2;
if (MIDI.read()) { // Is there a MIDI message incoming ?
uint8_t type = MIDI.getType();
switch (type) {
case midi::NoteOn:
note = MIDI.getData1();
velocity = MIDI.getData2();
channel = MIDI.getChannel();
if (velocity > 0) {
Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
} else {
Serial.println(String("Note Off: ch=") + channel + ", note=" + note);
}
break;
case midi::NoteOff:
note = MIDI.getData1();
velocity = MIDI.getData2();
channel = MIDI.getChannel();
Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity);
break;
default:
d1 = MIDI.getData1();
d2 = MIDI.getData2();
Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2);
}
t = millis();
}
if (millis() - t > 10000) {
t += 10000;
Serial.println("(inactivity)");
}
// --------------------------------Read Midi------------------------------------------------------------
}
Code:
'class midi::MidiInterface<midi::SerialMIDI<HardwareSerial> >' has no member named 'getData1'
how to fix it????