First my MidiDrum has sound without LCDI2C. Then I added the LCDI2C and five buttons (Edit, Up, Down, Next, Back) to my code, but it was no sound when hit any pad. Also press the five buttons and it’s no any action. Is the code wrong? I’m using Arduino Mega2560.
byte KICK[6] = {
100, //sensitivity (1-100)
55, //threshold (1-100)
25, //scan time (1-)
30, //mask time(1-)
36, //note (0-127)
1 //curve type(0-4)
};
byte TOM1[6] = {100, 55, 25, 30, 71, 1};
byte TOM2[6] = {100, 10, 10, 30, 69, 1};
/////////////////////////////////////////////////////////////////////////////////////
#include <hellodrum.h>
#include <LiquidCrystal_I2C.h>
//Using MIDI Library. If you want to use USB-MIDI, comment out the next two lines.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
LiquidCrystal_I2C lcd(0x27, 16, 2);
//Please name your piezo.
HelloDrum kick(0);
HelloDrum tom1(1);
HelloDrum tom2(2);
HelloDrumButton button(22, 24, 26, 28, 30); //(EDIT,UP,DOWN,NEXT,BACK)
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight(); //open the backlight
MIDI.begin();
Serial.begin(38400);
kick.settingName("KICK");
tom1.settingName("TOM 1");
tom2.settingName("TOM 2");
kick.loadMemory();
tom1.loadMemory();
tom2.loadMemory();
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Hello Drum");
}
void loop()
{
/////////// LCD & SETTING MODE /////////////
bool buttonPush = button.GetPushState();
bool editStart = button.GetEditState();
bool editDone = button.GetEditdoneState();
bool display = button.GetDisplayState();
const char *padName = button.GetPadName();
const char *item = button.GetSettingItem();
int settingValue = button.GetSettingValue();
int velocity = button.GetVelocity();
const char *hitPad = button.GetHitPad();
button.readButtonState();
kick.settingEnable();
tom1.settingEnable();
tom2.settingEnable();
if (buttonPush == true)
{
lcd.clear();
lcd.print(padName);
lcd.setCursor(0, 1);
lcd.print(item);
lcd.setCursor(13, 1);
lcd.print(settingValue);
}
if (editStart == true)
{
lcd.clear(); // clear display
lcd.print("EDIT START"); // print message at (0, 0)
delay(500); // display the above for 0.5 seconds
lcd.clear(); // clear display
lcd.print(padName); // print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (0, 1)
lcd.print(item); // print message at (0, 01)
lcd.setCursor(13, 1); // move cursor to (13, 1)
lcd.print(settingValue); // print message at (13, 1)
}
if (editDone == true)
{
lcd.clear();
lcd.print("EDIT DONE");
delay(500);
lcd.clear();
lcd.print(padName);
lcd.setCursor(0, 1);
lcd.print(item);
lcd.setCursor(13, 1);
lcd.print(settingValue);
}
//show hitted pad name and velocity to LCD
//Immediately after I2C communication, scanning of piezo is stop.
kick.singlePiezo();
tom1.singlePiezo();
tom2.singlePiezo();
//MIDI signals are transmitted with this IF statement.
//For each piezo, one IF statement is required
//kick
if (kick.hit == true)
{
MIDI.sendNoteOn(KICK[4], kick.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(KICK[4], 0, 10);
}
//tom 1
if (tom1.hit == true)
{
MIDI.sendNoteOn(TOM1[4], tom1.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(TOM1[4], 0, 10);
}
//tom 2
if (tom2.hit == true)
{
MIDI.sendNoteOn(TOM2[4], tom2.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(TOM2[4], 0, 10);
}
}