Problem with code
Problem with code Posted on: 26.12.2012 by Breann Gebhart Hello everybody,at the moment I try to build my own Traktor Midi Controller. I'm using a Teensy 2.0 because of the usbMIDI. I'm a absolute beginnner in Arduino programming but I found some code here http://www.instructables.com/id/PACM...tep2/Firmware/ and tried to change it a bit. I want 10 analog inputs and 14 digital inputs. Now my code looks like this: Code:
#include <Bounce.h> // pin definitions const int digital_pin[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 23 }; const int analog_pin[] = { A0, A1, A2, A3, A4, A5, A6, A7, A8, A9 }; // variables for the states of the controls boolean digital_stored_state[14]; int analog_stored_state[10]; // amount of change that constitutes sending a midi message // const int analog_threshold = 4; const int analog_scale = 8; // Debounce long debounceDelay = 5; Bounce digital_debouncer[] = { Bounce(digital_pin[0], debounceDelay), Bounce(digital_pin[1], debounceDelay), Bounce(digital_pin[2], debounceDelay), Bounce(digital_pin[3], debounceDelay), Bounce(digital_pin[4], debounceDelay), Bounce(digital_pin[5], debounceDelay), Bounce(digital_pin[6], debounceDelay), Bounce(digital_pin[7], debounceDelay), Bounce(digital_pin[8], debounceDelay), Bounce(digital_pin[9], debounceDelay), Bounce(digital_pin[10], debounceDelay), Bounce(digital_pin[11], debounceDelay), Bounce(digital_pin[22], debounceDelay), Bounce(digital_pin[23], debounceDelay), }; // MIDI settings int midi_ch = 3; int midi_vel = 127; const int digital_note[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61}; const int analog_control[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; void setup() { // set the pin modes && zero saved states int b = 0; // digital pins for (b = 14; b >= 0; b--) { pinMode(digital_pin[b], INPUT_PULLUP); digital_stored_state[b] = false; } // analog pins for (b = 10; b>= 0; b--) { analog_stored_state[b] = 0; } } void loop() { int b = 0; // digital pins for (b = 14; b >= 0; b--) { digital_debouncer[b].update(); boolean state = digital_debouncer[b].read(); if (state != digital_stored_state[b]) { if (state == false) { usbMIDI.sendNoteOn(digital_note[b], midi_vel, midi_ch); } else { usbMIDI.sendNoteOff(digital_note[b], midi_vel, midi_ch); } digital_stored_state[b] = !digital_stored_state[b]; } } // analog pins for (b = 10; b >= 0; b--) { int analog_state = analogRead(analog_pin[b]); if (analog_state - analog_stored_state[b] >= analog_scale || analog_stored_state[b] - analog_state >= analog_scale) { int scaled_value = analog_state / analog_scale; usbMIDI.sendControlChange(analog_control[b], scaled_value, midi_ch); analog_stored_state[b] = analog_state; } } } The problem is none of the analog inputs works right. Even when no poti is connected it spits out randomly midi data. The buttons work better. Except the button on PIN 3 sends two notes at once and the PINS 23 and 22 do nothing. I've tried to fix the problem, but it doesn't work. Can anybody help? | |
Breann Gebhart 26.12.2012 | Hello everybody, at the moment I try to build my own Traktor Midi Controller. I'm using a Teensy 2.0 because of the usbMIDI. I'm a absolute beginnner in Arduino programming but I found some code here http://www.instructables.com/id/PACM...tep2/Firmware/ and tried to change it a bit. I want 10 analog inputs and 14 digital inputs. Now my code looks like this: Code:
#include <Bounce.h> // pin definitions const int digital_pin[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 22, 23 }; const int analog_pin[] = { A0, A1, A2, A3, A4, A5, A6, A7, A8, A9 }; // variables for the states of the controls boolean digital_stored_state[14]; int analog_stored_state[10]; // amount of change that constitutes sending a midi message // const int analog_threshold = 4; const int analog_scale = 8; // Debounce long debounceDelay = 5; Bounce digital_debouncer[] = { Bounce(digital_pin[0], debounceDelay), Bounce(digital_pin[1], debounceDelay), Bounce(digital_pin[2], debounceDelay), Bounce(digital_pin[3], debounceDelay), Bounce(digital_pin[4], debounceDelay), Bounce(digital_pin[5], debounceDelay), Bounce(digital_pin[6], debounceDelay), Bounce(digital_pin[7], debounceDelay), Bounce(digital_pin[8], debounceDelay), Bounce(digital_pin[9], debounceDelay), Bounce(digital_pin[10], debounceDelay), Bounce(digital_pin[11], debounceDelay), Bounce(digital_pin[22], debounceDelay), Bounce(digital_pin[23], debounceDelay), }; // MIDI settings int midi_ch = 3; int midi_vel = 127; const int digital_note[] = { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61}; const int analog_control[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; void setup() { // set the pin modes && zero saved states int b = 0; // digital pins for (b = 14; b >= 0; b--) { pinMode(digital_pin[b], INPUT_PULLUP); digital_stored_state[b] = false; } // analog pins for (b = 10; b>= 0; b--) { analog_stored_state[b] = 0; } } void loop() { int b = 0; // digital pins for (b = 14; b >= 0; b--) { digital_debouncer[b].update(); boolean state = digital_debouncer[b].read(); if (state != digital_stored_state[b]) { if (state == false) { usbMIDI.sendNoteOn(digital_note[b], midi_vel, midi_ch); } else { usbMIDI.sendNoteOff(digital_note[b], midi_vel, midi_ch); } digital_stored_state[b] = !digital_stored_state[b]; } } // analog pins for (b = 10; b >= 0; b--) { int analog_state = analogRead(analog_pin[b]); if (analog_state - analog_stored_state[b] >= analog_scale || analog_stored_state[b] - analog_state >= analog_scale) { int scaled_value = analog_state / analog_scale; usbMIDI.sendControlChange(analog_control[b], scaled_value, midi_ch); analog_stored_state[b] = analog_state; } } } The problem is none of the analog inputs works right. Even when no poti is connected it spits out randomly midi data. The buttons work better. Except the button on PIN 3 sends two notes at once and the PINS 23 and 22 do nothing. I've tried to fix the problem, but it doesn't work. Can anybody help? |
<< Back to Reviews of DJ equipment Reply