Salve, ho quasi scritto questo.. ma non capisco cosa ha il software:
hairless-midiserial (Per utilizzare arduino con MIDI).
Che se lancio il programma insieme ad mixxx .. subito dopo in 3 secondi mi si chiude.
ecco il codice:
button.cpp
#include "Button.h"
Button::Button(byte pin) {
this->pin = pin;
lastReading = LOW;
init();
}
void Button::init() {
pinMode(pin, INPUT);
update();
}
void Button::update() {
byte newReading = digitalRead(pin);
if (newReading != lastReading) {
lastDebounceTime = millis();
}
if (millis() - lastDebounceTime > debounceDelay) {
state = newReading;
}
lastReading = newReading;
}
byte Button::getState() {
update();
return state;
}
bool Button::isPressed() {
return (getState() == HIGH);
}
Button.h
#ifndef MY_BUTTON_H
#define MY_BUTTON_H
#include <Arduino.h>
class Button {
private:
byte pin;
byte state;
byte lastReading;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
public:
Button(byte pin);
void init();
void update();
byte getState();
bool isPressed();
};
#endif
Main.ino
#include <MIDI.h>
#include "button.h"
MIDI_CREATE_DEFAULT_INSTANCE();
#define buttonNumber 6
Button Buttons[buttonNumber] = { Button(2), Button(3), Button(4), Button(5), Button(6), Button(7) };
byte buttonsNote[buttonNumber] = { 36, 23, 8, 9, 10, 11 };
byte statusNote[buttonNumber] = {0, 0, 0, 0, 0, 0};
void setup() {
Serial.begin(115200);
delay(100);
}
void loop() {
if(Buttons[i].isPressed())
{
MIDI.sendNoteOn(buttonsNote[i], 127, 1);
}else{
MIDI.sendNoteOff(buttonsNote[i], 0, 1);
}
}
Poi visto che ho fatto solo o meglio ho studiato la base del c++. ma non so come farlo qui.
Vorrei fare un for int i = 0; i<buttonNumber; i++;
e metterlo in
if(Buttons[i].isPressed())
{
ma solo che quando carico e apro il trasformatore da seriale a midi.. esce di colpo senza darmi l'avviso.
Avete idea come posso vedere ?
Ho libro dei progetti comprato su qui nello store ufficiale.
Grazie mille.