Hi all, i'm try to upload the code to Arduino UNO but got warning mean the sketch is too big. I don't know how to reduce the sketch. Please help me to solve this problem
Waring message
"text section exceeds available space in boardSketch uses 17072 bytes (52%) of program storage space. Maximum is 32256 bytes.
Global variables use 2446 bytes (119%) of dynamic memory, leaving -398 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 22 for tips on reducing it."
#define Drum_map 0
// ADD2 MAP
byte Note[2][21] = {{
36, 38, 37, 42, 54, 49, 48, 71, 69, 67, 65,
60, 62, 61, 77, 79, 81, 89, 91, 93
}
};
//sensitivity, threshold, scan time, mask time, note map
uint8_t KICK[5] = {100, 10, 10, 30, Note[Drum_map][0]};
uint8_t SNARE[9] = {100, 10, 30, 10, 10, 3, Note[Drum_map][1], Note[Drum_map][2], Note[Drum_map][3]};
uint8_t HIHAT[6] = {100, 10, 10, 30, Note[Drum_map][4], Note[Drum_map][5]};
uint8_t HIHAT_PEDAL[5] = {90, 30, 70, 90, Note[Drum_map][6]};
uint8_t TOM1[5] = {100, 55, 25, 30, Note[Drum_map][7]};
uint8_t TOM2[5] = {100, 55, 25, 30, Note[Drum_map][8]};
uint8_t TOM3[5] = {100, 55, 25, 30, Note[Drum_map][9]};
uint8_t TOM4[5] = {100, 55, 25, 30, Note[Drum_map][10]};
uint8_t RIDE[9] = {100, 10, 10, 30, 4, 9, Note[Drum_map][11], Note[Drum_map][12], Note[Drum_map][13]};
uint8_t CRASH[9] = {100, 10, 10, 30, 4, 9, Note[Drum_map][14], Note[Drum_map][15], Note[Drum_map][16]};
uint8_t CYM1[5] = {100, 10, 10, 30, Note[Drum_map][17]};
uint8_t CYM2[5] = {100, 10, 10, 30, Note[Drum_map][18]};
uint8_t CHINA[5] = {100, 10, 10, 30, Note[Drum_map][19]};
/////////////////////////////////////////////////////////////////////////////////////
#include <hellodrum.h>
#include <LiquidCrystal_I2C.h>
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
LiquidCrystal_I2C lcd(0x27, 16, 2);
HelloDrumMUX_4067 mux(2, 3, 4, 5, 0);
//name pad and define MUX pin
HelloDrum kick(0);
HelloDrum snare(1, 2);
HelloDrum hihat(4);
HelloDrum hihatPedal(3);
HelloDrum tom1(5);
HelloDrum tom2(6);
HelloDrum tom3(7);
HelloDrum tom4(12);
HelloDrum ride(8, 9);
HelloDrum crash(10, 11);
HelloDrum cym1(13);
HelloDrum cym2(14);
HelloDrum china(15);
HelloDrumButton button(8, 9, 10, 11, 12);
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight(); //open the backlight
MIDI.begin();
Serial.begin(38400);
kick.settingName("KICK");
snare.settingName("SNARE");
hihat.settingName("HIHAT");
hihatPedal.settingName("HIHAT PEDAL");
tom1.settingName("TOM 1");
tom2.settingName("TOM 2");
tom3.settingName("TOM 3");
tom4.settingName("TOM 4");
ride.settingName("RIDE");
crash.settingName("CRASH");
cym1.settingName("CYMBAL 1");
cym2.settingName("CYMBAL 2");
china.settingName("CHINA");
//splash.settingName("SPLASH");
kick.loadMemory();
snare.loadMemory();
hihat.loadMemory();
hihatPedal.loadMemory();
tom1.loadMemory();
tom2.loadMemory();
tom3.loadMemory();
tom4.loadMemory();
ride.loadMemory();
crash.loadMemory();
cym1.loadMemory();
cym2.loadMemory();
china.loadMemory();
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Hello world!");
lcd.setCursor(0, 1);
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();
snare.settingEnable();
hihat.settingEnable();
hihatPedal.settingEnable();
tom1.settingEnable();
tom2.settingEnable();
tom3.settingEnable();
tom4.settingEnable();
ride.settingEnable();
crash.settingEnable();
cym1.settingEnable();
cym2.settingEnable();
china.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);
}
mux.scan();
kick.singlePiezoMUX();
snare.dualPiezoMUX();
hihat.HHMUX();
hihatPedal.TCRT5000MUX();
tom1.singlePiezoMUX();
tom2.singlePiezoMUX();
tom3.singlePiezoMUX();
tom4.singlePiezoMUX();
ride.cymbal3zoneMUX();
crash.cymbal2zoneMUX();
cym1.singlePiezoMUX();
cym2.singlePiezoMUX();
china.singlePiezoMUX();
//Kick
if (kick.hit == true)
{
MIDI.sendNoteOn(KICK[4], kick.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(KICK[4], 0, 10);
}
//SNARE HEAD
if (snare.hit == true)
{
MIDI.sendNoteOn(SNARE[6], snare.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(SNARE[6], 0, 10);
}
//SNARE RIMSHOT
else if (snare.hitRim == true)
{
if (snare.velocity > 60)
{
MIDI.sendNoteOn(SNARE[7], snare.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(SNARE[7], 0, 10);
}
else
{
MIDI.sendNoteOn(SNARE[8], snare.velocity * 2, 10); //(note, velocity, channel)
MIDI.sendNoteOff(SNARE[8], 0, 10);
}
}
//HiHat
if (hihat.hit == true)
{
//check open or close
//1.open
if (hihatPedal.openHH == true)
{
MIDI.sendNoteOn(HIHAT[4], hihat.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(HIHAT[4], 0, 10);
}
//2.close
else if (hihatPedal.closeHH == true)
{
MIDI.sendNoteOn(HIHAT[5], hihat.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(HIHAT[5], 0, 10);
}
}
//when pedal is closed, TCRT5000
if (hihatPedal.hit == true)
{
MIDI.sendNoteOn(HIHAT_PEDAL[4], hihatPedal.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(HIHAT_PEDAL[4], 0, 10);
}
//sending state of pedal with controll change
if (hihatPedal.moving == true)
{
MIDI.sendControlChange(4, hihatPedal.pedalCC, 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);
}
//Tom 3
if (tom3.hit == true)
{
MIDI.sendNoteOn(TOM3[4], tom3.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(TOM3[4], 0, 10);
}
//Tom 4
if (tom4.hit == true)
{
MIDI.sendNoteOn(TOM4[4], tom4.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(TOM4[4], 0, 10);
}
//Ride Bow
if (ride.hit == true)
{
MIDI.sendNoteOn(RIDE[6], ride.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(RIDE[6], 0, 10);
}
//Ride Edge
else if (ride.hitRim == true)
{
MIDI.sendNoteOn(RIDE[7], ride.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(RIDE[7], 0, 10);
}
//Ride Cup
else if (ride.hitCup == true)
{
MIDI.sendNoteOn(RIDE[8], ride.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(RIDE[8], 0, 10);
}
//Ride Choke
if (ride.choke == true)
{
MIDI.sendPolyPressure(RIDE[6], 127, 10);
MIDI.sendPolyPressure(RIDE[7], 127, 10);
MIDI.sendPolyPressure(RIDE[8], 127, 10);
MIDI.sendPolyPressure(RIDE[6], 0, 10);
MIDI.sendPolyPressure(RIDE[7], 0, 10);
MIDI.sendPolyPressure(RIDE[8], 0, 10);
}
//Crash Bow
if (crash.hit == true)
{
MIDI.sendNoteOn(CRASH[6], crash.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CRASH[6], 0, 10);
}
//Crash Edge
else if (crash.hitRim == true)
{
MIDI.sendNoteOn(CRASH[7], crash.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CRASH[7], 0, 10);
}
//Crash Cup
else if (crash.hitCup == true)
{
MIDI.sendNoteOn(CRASH[8], crash.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CRASH[8], 0, 10);
}
//Crash Choke
if (crash.choke == true)
{
MIDI.sendPolyPressure(CRASH[6], 127, 10);
MIDI.sendPolyPressure(CRASH[7], 127, 10);
MIDI.sendPolyPressure(CRASH[8], 127, 10);
MIDI.sendPolyPressure(CRASH[6], 0, 10);
MIDI.sendPolyPressure(CRASH[7], 0, 10);
MIDI.sendPolyPressure(CRASH[8], 0, 10);
}
//Cymbal
if (cym1.hit == true)
{
MIDI.sendNoteOn(CYM1[4], cym1.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CYM1[4], 0, 10);
}
if (cym2.hit == true)
{
MIDI.sendNoteOn(CYM2[4], cym2.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CYM2[4], 0, 10);
}
if (china.hit == true)
{
MIDI.sendNoteOn(CHINA[4], china.velocity, 10); //(note, velocity, channel)
MIDI.sendNoteOff(CHINA[4], 0, 10);
}
}