Anyone know why this code will not work on all analog inputs? I have a teensy 3.6 that has 22 analog inputs most have piezos connected to trigger midi notes. pins 14-22 won't work, I tested the pins on another program and they all work showing the voltage jump on the serial monitor when taped same as the others. Is there something in the code?
[code]
/*
MIDIUSB_test.ino
Created: 4/6/2015 10:47:08 AM
Author: gurbrinder grewal
Modified by Arduino LLC (2015) & Grumpy Mike
*/
#include "MIDIUSB.h"
// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
void setup() {
Serial.begin(115200);
}
// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).
void loop() {
int val;
val = analogRead(0);
if (val > 600) { // if it is greater than the threshold
noteOn(0, 50, 127); // send a note on message the 68 is the pitch of the note
MidiUSB.flush(); // send the MIDI message
while (analogRead(0) > 600) { } // wait here until the signal has dropped
noteOff(0, 50, 127); // send the note off message
}
MidiUSB.flush(); // send the MIDI message
{
int val;
val = analogRead(1);
if (val > 600) {
noteOn(0, 51, 127);
MidiUSB.flush();
while (analogRead(1) > 600) { }
noteOff(0, 51, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(2);
if (val > 600) {
noteOn(0, 52, 127);
MidiUSB.flush();
while (analogRead(2) > 600) { }
noteOff(0, 52, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(3);
if (val > 600) {
noteOn(0, 53, 127);
MidiUSB.flush();
while (analogRead(3) > 600) { }
noteOff(0, 53, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(4);
if (val > 600) {
noteOn(0, 54, 127);
MidiUSB.flush();
while (analogRead(4) > 600) { }
noteOff(0, 54, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(5);
if (val > 600) {
noteOn(0, 55, 127);
MidiUSB.flush();
while (analogRead(5) > 600) { }
noteOff(0, 55, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(6);
if (val > 600) {
noteOn(0, 56, 127);
MidiUSB.flush();
while (analogRead(6) > 600) { }
noteOff(0, 56, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(7);
if (val > 600) {
noteOn(0, 57, 127);
MidiUSB.flush();
while (analogRead(7) > 600) { }
noteOff(0, 57, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(8);
if (val > 600) {
noteOn(0, 58, 127);
MidiUSB.flush();
while (analogRead(8) > 600) { }
noteOff(0, 58, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(9);
if (val > 600) {
noteOn(0, 59, 127);
MidiUSB.flush();
while (analogRead(9) > 600) { }
noteOff(0, 59, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(10);
if (val > 600) {
noteOn(0, 60, 127);
MidiUSB.flush();
while (analogRead(10) > 600) { }
noteOff(0, 60, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(11);
if (val > 600) {
noteOn(0, 61, 127);
MidiUSB.flush();
while (analogRead(11) > 600) { }
noteOff(0, 61, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(12);
if (val > 600) {
noteOn(0, 62, 127);
MidiUSB.flush();
while (analogRead(12) > 600) { }
noteOff(0, 62, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(13);
if (val > 600) {
noteOn(0, 63, 127);
MidiUSB.flush();
while (analogRead(13) > 600) { }
noteOff(0, 63, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(14);
if (val > 600) {
noteOn(0, 64, 127);
MidiUSB.flush();
while (analogRead(14) > 600) { }
noteOff(0, 64, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(15);
if (val > 600) {
noteOn(0, 65, 127);
MidiUSB.flush();
while (analogRead(15) > 600) { }
noteOff(0, 65, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(16);
if (val > 600) {
noteOn(0, 66, 127);
MidiUSB.flush();
while (analogRead(16) > 600) { }
noteOff(0, 66, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(17);
if (val > 600) {
noteOn(0, 67, 127);
MidiUSB.flush();
while (analogRead(17) > 600) { }
noteOff(0, 67, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(18);
if (val > 600) {
noteOn(0, 68, 127);
MidiUSB.flush();
while (analogRead(18) > 600) { }
noteOff(0, 68, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(19);
if (val > 600) {
noteOn(0, 69, 127);
MidiUSB.flush();
while (analogRead(19) > 600) { }
noteOff(0, 69, 127);
} 9
MidiUSB.flush();
}
{
int val;
val = analogRead(20);
if (val > 600) {
noteOn(0, 70, 127);
MidiUSB.flush();
while (analogRead(20) > 600) { }
noteOff(0, 70, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(21);
if (val > 600) {
noteOn(0, 71, 127);
MidiUSB.flush();
while (analogRead(21) > 600) { }
noteOff(0, 71, 127);
}
MidiUSB.flush();
}
{
int val;
val = analogRead(22);
if (val > 600) {
noteOn(0, 72, 127);
MidiUSB.flush();
while (analogRead(22) > 600) { }
noteOff(0, 72, 127);
}
MidiUSB.flush();
}
}
[/code]