Closed HaViGit closed 2 months ago
Funny. Teensy 4.0 is supposed to ignore the bit of code that refers to touchRead because it doesn't feature capacitive touch. Can you post your sketch?
Thanks for your quick response. The code is taken 1:1 from the MIDIswitch_toggle.ino demo (see below) of the library. Please let me know if you need more information.
/*
This example will show how to use a switch to toggle between two different
MIDI messages. It could allow a switch to toggle START and STOP for example.
*/
#include "MIDIcontroller.h"
byte MIDIchannel = 5;
const int switchPin = 2;
const int ledPin = 13; //Set an LED to show the state of the input.
bool state = false;
MIDIswitch myInput(switchPin, START); // Don't use LATCH
void setup(){
pinMode(ledPin, OUTPUT);
}
void loop(){
if ( myInput.send() > -1) { // no input == -1
state = !state;
if (state) myInput.setControlNumber(STOP);
else myInput.setControlNumber(START);
}
digitalWrite(ledPin, state); // LED indicates state
// This prevents crashes that happen when incoming usbMIDI is ignored.
while(usbMIDI.read()){}
// Also uncomment this if compiling for standard MIDI
// while(MIDI.read()){}
}
I forgot that I even implemented realtime messages. START and STOP should work fine and that wouldn't cause an error about touchRead anyway... Still thinking.
A little more information about my wishes. The controller I am building is not that complex, for my software (Vengeance Avenger) I only want to use three sliders and two toggle buttons for the synth macros. The sliders now work with the sketch below, I would also like to use two toggle buttons.
#include "MIDIcontroller.h"
byte MIDIchannel = 5;
const int potPin1 = A0;
const int potPin2 = A1;
const int potPin3 = A2;
const int ledPin = 12;
MIDIpot myPot1(potPin1, 9);
MIDIpot myPot2(potPin2, 14);
MIDIpot myPot3(potPin3, 15);
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(115200);
delay(500);
myPot1.outputRange(127, 0);
myPot2.outputRange(127, 0);
myPot3.outputRange(127, 0);
digitalWrite(ledPin, HIGH);
}
void loop(){
myPot1.send();
myPot2.send();
myPot3.send();
while(usbMIDI.read()) {}
}
Okay, I think I got it. The constructor that only takes a pin number and CC number was creating an unnecessary 'TouchSwitch' object. On boards that feature touchRead, the only problem is that it took up a bit of extra memory. Boards that don't feature touchRead threw errors. Should be fixed in version 3.1.2 now.
Thanks Josh!
The official release for version 3.1.3 of this library should more properly address any issues with using 4.x boards. Please open a new issue about any problems you encounter with that release.
Hi Josh,
First of all thanks for sharing this library, the MIDIpot example worked for me without a doubt.
Unfortunately I get error messages with the MIDIswitch_toggle example, below you can see the error code. I use Arduiono IDE 2.2.1 and a Teensy 4.0 board with board manager https://www.pjrc.com/teensy/package_teensy_index.json.
Can you help me solve this?