Bonjour,
J'ai monté un petit contrôleur midi avec 1 joystick, 6 boutons d'arcade, et 2 potentiomètres sur 1 arduino leonardo. La transmission se fait par USBMIDI.
Tout fonctionne, sauf que j'ai parfois de fausses détections, surtout avec le joystick, il détecte parfois 2 clic, alors qu'il n'y en a eu qu'un.
J'ai donc modifié mon code avec la bibliothèque bounce, mais j'ai cette erreur que je ne comprends pas lors de la vérification :
exit status 1
expected unqualified-id before 'for'
l'erreur pointe sur cette ligne :
for (int i=0; i<BUTTON_PIN_COUNT; ++i) { Bounce bouton[i] = Bounce(); }
voici le code complet :
#include <midi_serialization.h>
#include <usbmidi.h>
#include <Bounce2.h>
// See midictrl.png in the example folder for the wiring diagram,
// as well as README.md.
void sendCC(uint8_t channel, uint8_t control, uint8_t value) {
USBMIDI.write(0xB0 | (channel & 0xf));
USBMIDI.write(control & 0x7f);
USBMIDI.write(value & 0x7f);
}
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity) {
USBMIDI.write((velocity != 0 ? 0x90 : 0x80) | (channel & 0xf));
USBMIDI.write(note & 0x7f);
USBMIDI.write(velocity & 0x7f);
}
const int ANALOG_PIN_COUNT = 2;
const int BUTTON_PIN_COUNT = 10;
// Change the order of the pins to change the ctrl or note order.
//int testBtn;
int analogPins[ANALOG_PIN_COUNT] = { A1, A0 };
int buttonPins[BUTTON_PIN_COUNT] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int ccValues[ANALOG_PIN_COUNT];
int buttonDown[BUTTON_PIN_COUNT];
int bouton[BUTTON_PIN_COUNT];
for (int i = 0; i < BUTTON_PIN_COUNT; ++i) {
Bounce bouton[i] = Bounce();
}
int readCC(int pin) {
// Convert from 10bit value to 7bit.
return analogRead(pin) >> 3;
}
int isButtonDown(int pin) {
return bouton[pin].read() == 0;
}
void setup() {
// Initialize initial values.
for (int i = 0; i < ANALOG_PIN_COUNT; ++i) {
pinMode(analogPins[i], INPUT);
ccValues[i] = readCC(analogPins[i]);
}
for (int i = 0; i < BUTTON_PIN_COUNT; ++i) {
bouton[i].attach(buttonPins[i], INPUT_PULLUP);
bouton[i].interval(5);
//pinMode(buttonPins[i], INPUT);
//digitalWrite(buttonPins[i], HIGH);
buttonDown[i] = isButtonDown(i);
}
}
void loop() {
//Handle USB communication
USBMIDI.poll();
while (USBMIDI.available()) {
// We must read entire available data, so in case we receive incoming
// MIDI data, the host wouldn't get stuck.
u8 b = USBMIDI.read();
}
for (int i = 0; i < BUTTON_PIN_COUNT; ++i) {
bouton[i].update();
}
for (int i = 0; i < ANALOG_PIN_COUNT; ++i) {
int value = readCC(analogPins[i]);
//int value1 = readCC(analogPins[1]);
// Send CC only if th has changed.
if (ccValues[i] != value) {
sendCC(0, i, value);
ccValues[i] = value;
}
}
for (int i = 0; i < 4; ++i) {
int down = isButtonDown(i);
if (down != buttonDown[i]) {
sendNote(0, 64 + i, down ? 120 : 0);
buttonDown[i] = down;
}
}
for (int i = 4; i < 10; ++i) {
//testBtn = digitalRead(buttonPins[i]);
//Serial.println(buttonPins[i]);
//Serial.println(testBtn);
int down = isButtonDown(i);
int note = i;
note = map(note, 5, 10, 0, 5);
if (down != buttonDown[i]) {
sendNote(1, 24 + note, down ? 120 : 0);
buttonDown[i] = down;
}
}
// Flush the output.
USBMIDI.flush();
}
Si quelqu'un peut m'expliquer, et m'aider à résoudre le problème ?
Merci